Count

Count( arrayOrSet )
Count( arrayOrSet )
Count( arrayOrSet )
Count( arrayOrSet )
count( arrayOrSet )
Count( arrayOrSet )

Description

The Count function returns the number of items that exist in arrayOrSet, which is an Array, Page, or Set.

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

To work around this, you may specify a larger query timeout via the driver that you are using.

Parameters

Argument Type Definition and Requirements

arrayOrSet

Array, Page, or Set

The array, page, or set that should have its items counted.

Returns

The Number of items in arrayOrSet.

Examples

The following query returns the number of items in the provided array:

Value result = await client.Query(
  Count(Arr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
);

IResult<Value> data = result.To<Value>();
data.Match(
  Success: value => Console.WriteLine($"{value}"),
  Failure: error => Console.WriteLine($"Query failed:\n{error}")
);
LongV(10)
result, err := client.Query(
  f.Count(f.Arr{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}))

if (err != nil) {
  fmt.Println(err)
} else {
  fmt.Println(result)
}
10
System.out.println(
    client.query(
        Count(
            Arr(
                Value(1), Value(2), Value(3), Value(4), Value(5),
                Value(6), Value(7), Value(8), Value(9), Value(10)
            )
        )
    ).get()
);
10
client.query(
  q.Count([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
)
.then((ret) => console.log(ret))
10
print(client.query(
  q.count([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
))
10
println(Await.result(
  client.query(
    Count(Arr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
  ),
  5.seconds)
)
10

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!