ContainsPath
ContainsPath( path, in )
ContainsPath( path, in )
ContainsPath( path, in )
ContainsPath(path, in )
contains_path(path, in )
ContainsPath(path, in )
Description
The ContainsPath
function returns true
if the specified path
exists
within the result of the in
expression, or false
otherwise.
ContainsPath
is useful when you need to distinguish between objects,
arrays, or documents that contain a nested path and those that do not.
The path
is an array containing path selectors. Each path selector is
a number (representing an array offset) or a string (representing a field
name). The path is evaluated from left to right, and each path selector
after the first represents a nesting within the data structure of the
result of the in
expression.
For example, if you provide the path 0, a, 1, b
, the result of the
in
expression has to be an array where the first item is an object
with the field a
, whose value is an array and the second item in that
array is an object with the field b
. The minimal structure that would
satisfy that path is:
[
{
"a": [
{},
{ "b": true }
]
}
]
Examples
-
Array offsets
The following query returns
true
because the path1, 2
(targeting the valuec
) exists within the provided array:BooleanV(True)
true
true
true
True
true
-
Field names
The following query returns
true
because the pathb, two
exists because the provided object has ab
field that contains an object with thetwo
field:BooleanV(True)
true
true
true
True
true
-
Mixing field names and array offsets
The following query returns
true
because the path2, first
(which refers to the field containingGrace
) exists in the provided array:BooleanV(True)
true
true
true
True
true
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!