GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Close
  • FAQ
  • Docs
  • API
  • Community
  • Blog
  • Accessing ReQL
  • r
  • connect
  • close
  • reconnect
  • use
  • run
  • changes

This view

  • Original page
  • New address

GeezerVison is showing rethinkdb.com — ReQL command reference - RethinkDB


▲ Back to top

Command syntax

sequence.count([value | predicate_function]) → number

binary.count() → number

string.count() → number

object.count() → number

array.count() → number

r.count(sequence | binary | string | object[, predicate_function]) → number

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, callback);

Example: Count the number of 18 year old users.

r.table('users')('age').count(18).run(conn, callback);

Example: Count the number of users over 18.

r.table('users')('age').count(function(age) { 
    return age.gt(18)
}).run(conn, callback);
r.table('users').count(function(user) {
    return user('age').gt(18)
}).run(conn, callback)

Example: Return the length of a Unicode string.

r.expr("こんにちは").count().run(conn, callback);
// Result passed to callback
5

Example: Return the length of an array.

r.expr(['0','1','2']).count().run(conn, callback);
// Result passed to callback
3

Related commands

  • map
  • reduce
  • sum
  • avg
  • min
  • max
  • group

Get more help

Couldn't find what you were looking for?

  • Ask a question on Stack Overflow
  • Chat with us and our community on Slack
  • Talk to the team on IRC on #[email protected] — via Webchat
  • Ping @rethinkdb on Twitter
  • Post an issue on the documentation issue tracker on GitHub

Contribute: edit this page or open an issue

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.