ContainsValue

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

ContainsValue( value, in )
ContainsValue( value, in )
ContainsValue( value, in )
containsValue( value, in )
ContainsValue( value, in )

Description

The ContainsValue function returns true if the specified value exists within the result of the in expression, or false otherwise.

ContainsValue is useful when you need to distinguish between object, arrays, or documents that contain a value (regardless of field name) and those that do not.

ContainsValue does not evaluate nested arrays or objects. If you need to determine whether a value exists within a complex structure, the Select function can be used to target the appropriate section within a structure.

Parameters

Parameter Type Definition and Requirements

value

Any

A value of any type.

in

Any

A value of any type.

Returns

A Boolean value that indicates whether value exists within in.

Examples

The following query returns true because the value 3 exists in the provided object:

try
{
    Value result = await client.Query(
        ContainsValue(
            3,
            Obj(
                "a", 1,
                "b", 2,
                "c", 3
            )
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
BooleanV(True)
result, err := client.Query(
	f.ContainsValue(
		3,
		f.Obj{
			"a": 1,
			"b": 2,
			"c": 3 }))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
true
client.query(
  q.ContainsValue(
    3,
    {
      a: 1,
      b: 2,
      c: 3,
    },
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
true
result = client.query(
  q.contains_value(
    3,
    {
      "a": 1,
      "b": 2,
      "c": 3
    }
  )
)
print(result)
True
ContainsValue(
  3,
  {
    'a': 1,
    'b': 2,
    'c': 3,
  },
)
true
Query metrics:
  •    bytesIn:  56

  •   bytesOut:  17

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 1ms

  •    retries:   0

The following query returns false because the value 7 does not exist in the provided object:

try
{
    Value result = await client.Query(
        ContainsValue(
            7,
            Obj(
                "a", 1,
                "b", 2,
                "c", 3
            )
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
BooleanV(False)
result, err := client.Query(
	f.ContainsValue(
		7,
		f.Obj{
			"a": 1,
			"b": 2,
			"c": 3 }))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
false
client.query(
  q.ContainsValue(
    7,
    {
      a: 1,
      b: 2,
      c: 3,
    },
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
false
result = client.query(
  q.contains_value(
    7,
    {
      "a": 1,
      "b": 2,
      "c": 3
    }
  )
)
print(result)
False
ContainsValue(
  7,
  {
    'a': 1,
    'b': 2,
    'c': 3,
  },
)
false
Query metrics:
  •    bytesIn:  56

  •   bytesOut:  18

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 2ms

  •    retries:   0

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!