FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

For more details, review the migration guide. Contact support@fauna.com with any questions.

Any

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

Any( values )
any( values )
Any( values )
Any( values )
Any( values )

Description

The Any function tests the provided values and returns true if any of the items in values is true, otherwise it returns false.

When values is an empty Array or Set, Any returns false, because values contains no true values.

Any is a better choice for handling collections of values than the similar Or function.

The run time of Any is dependent on the number of elements in the underlying set or page — it’s linear, or O(n). For very large sets or pages, executing Any might result in a query timeout error, or "width" error.

For query "width" errors, the underlying set or page involves more than 100K items. This can happen when using a set function, such as Difference, where more than 100K items need to be considered to produce the set that Any evaluates. To resolve this, use Paginate to limit the set or page size.

For example, instead of:

Any(
  Difference(
    Match(Index("Index1"), "term1"),
    Match(Index("Index2"), "term2")
  )
)

use:

Any(
  Paginate(
    Difference(
      Match(Index("Index1"), "term1"),
      Match(Index("Index2"), "term2")
    ),
    { size: 10000 }
  )
)

This does mean that if the entire set must be evaluated to arrive at the correct result, you would have to page through the Paginate results.

For query timeout errors, you may specify a larger query timeout via the driver that you are using.

Parameters

Parameter Type Definition and Requirements

values

Array or Set

A group of values to test for being true.

Returns

A Boolean indicating whether any of the items in values is true.

Examples

The following query uses Any multiple times to demonstrate how the function evaluates several groups of values:

client.query([
  q.Any([true, true, true]),
  q.Any([false, true, true]),
  q.Any([false, false, false]),
  q.Any([]),
])
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ true, true, false, false ]
result = client.query(
  [
    q.any([True, True, True]),
    q.any([False, True, True]),
    q.any([False, False, False]),
    q.any([]),
  ]
)
print(result)
[True, True, False, False]
result, err := client.Query(
	f.Arr{
		f.Any(f.Arr{true, true, true}),
		f.Any(f.Arr{false, true, true}),
		f.Any(f.Arr{false, false, false}),
		f.Any(f.Arr{}),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[true true false false]
try
{
    Value result = await client.Query(
        Arr(
            Any(Arr(true, true, true)),
            Any(Arr(false, true, true)),
            Any(Arr(false, false, false)),
            Any(Arr())
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(BooleanV(True), BooleanV(True), BooleanV(False), BooleanV(False))
[
  Any([true, true, true]),
  Any([false, true, true]),
  Any([false, false, false]),
  Any([])
]
[ true, true, false, false ]
Query metrics:
  •    bytesIn:  91

  •   bytesOut:  36

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 4ms

  •    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!