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"))
    )));
true
curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "contains": [ "favorites", "foods" ],
          "in": {
            "object": {
              "favorites": {
                "object": { "foods": [ "crunchings", "munchings", "lunchings" ] }
              }
            }
          }
        }'
HTTP/1.1 200 OK
{ "resource": true }
result, _ := client.Query(
    f.Contains(
        f.Arr{"favorites", "foods"},
        f.Obj{
            "favorites": f.Obj{
                "foods": f.Arr{"crunchings", "munchings", "lunchings"},
            },
        },
    ),
)

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))
true
client.query(
  q.contains(
    ["favorites", "foods"],
    {
      "favorites": {"foods": ["crunchings", "munchings", "lunchings"]}
    }
  ))
true
client.query(
  Contains(
    Arr("favorites", "foods"),
    Obj(
      "favorites" -> Obj("foods" -> Arr("crunchings", "munchings", "lunchings"))
    )))
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!