Contains

Contains( path, in )
Contains( path, in )
Contains( path, in )
Contains( path, in )
contains( path, in )
Contains( path, in )

Description

The Contains function returns true if the argument passed as in contains a value at the specified path, and false otherwise.

This function is deprecated. You should use its alias ContainsPath instead, or the related ContainsField and ContainsValue functions.

Parameters

Argument Type Definition and Requirements

path

Array of Numbers and/or Strings

A path to a specified field or array entry within the in value.

in

Any

A value of any type.

Returns

A boolean value.

Examples

The following query returns true because the path favorites.foods exists in the provided object:

client.Query(
    Contains(
        Arr("favorites", "foods"),
        Obj(
            "favorites", Obj(
                "foods", Arr(
                    "crunchings", "munchings", "lunchings"
                )
            )
        )
    )
);
BooleanV(True)
result, err := client.Query(
	f.Contains(
		f.Arr{"favorites", "foods"},
		f.Obj{
			"favorites": f.Obj{
				"foods": f.Arr{"crunchings", "munchings", "lunchings"}}}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
true
System.out.println(
    client.query(
        Contains(
            Arr(Value("favorites"), Value("foods")),
            Obj(
                "favorites", Obj(
                    "foods", Arr(
                        Value("crunchings"),
                        Value("munchings"),
                        Value("lunchings")
                    )
                )
            )
        )
    ).get());
true
client.query(
  q.Contains(
    ['favorites', 'foods'],
    {
      favorites: {
        foods: ['crunchings', 'munchings', 'lunchings'],
      },
    },
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
true
result = client.query(
  q.contains(
    ["favorites", "foods"],
    {
      "favorites": {
        "foods": ["crunchings", "munchings", "lunchings"]
      }
    }
  )
)
print(result)
True
client.query(
  Contains(
    Arr("favorites", "foods"),
    Obj(
      "favorites" -> Obj(
        "foods" -> Arr("crunchings", "munchings", "lunchings")
      )
    )
  )
)
true

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!