Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 1.58 KB

File metadata and controls

61 lines (46 loc) · 1.58 KB
layout language permalink command related_commands
api-command
Java
api/java/count/
count
map reduce sum avg min max group
map/
reduce/
sum/
avg/
min/
max/
group/

Command syntax

{% apibody %} sequence.count([value | predicate_function]) → number binary.count() → number string.count() → number object.count() → number r.count(sequence | binary | string | object[, predicate_function]) → number {% endapibody %}

Description

Counts the number of elements in a sequence or key/value pairs in an object, or returns the size of a string or binary object.

When count is called on a sequence with a predicate value or function, it returns the number of elements in the sequence equal to that value or where the function returns true. On a binary object, count returns the size of the object in bytes; on strings, count returns the string's length. This is determined by counting the number of Unicode codepoints in the string, counting combining codepoints separately.

Example: Count the number of users.

r.table("users").count().run(conn);

Example: Count the number of 18 year old users.

r.table("users").g("age").count(18).run(conn);

Example: Count the number of users over 18.

r.table("users").g("age").count(age -> age.gt(18)).run(conn);

Alternatively:

r.table("users").count(user -> user.g("age").gt(18)).run(conn);

Example: Return the length of a Unicode string.

r.expr("こんにちは").count().run(conn);
// returns: 5