RethinkDB.Query

Querying API for RethinkDB

Summary

Functions

Add multiple values

Sum two numbers, concatenate two strings, or concatenate 2 arrays

Compute the logical “and” of all values in a list

Compute the logical “and” of two values

Append a value to an array

args is a special term that’s used to splice an array of arguments into another term. This is useful when you want to call a variadic term such as get_all with a set of arguments produced at runtime

Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns None or a non-existence error

Get all documents between two keys. Accepts three optional arguments: index, left_bound, and right_bound. If index is set to the name of a secondary index, between will return all documents where that index’s value is in the specified range (it uses the primary key by default). left_bound or right_bound may be set to open or closed to indicate whether or not to include that endpoint of the range (by default, left_bound is closed and right_bound is open)

Encapsulate binary data within a query

If the test expression returns False or None, the false_branch will be evaluated. Otherwise, the true_branch will be evaluated

Rounds the given value up, returning the smallest integer value greater than or equal to the given value (the value’s ceiling)

Change a value in an array at a given index. Returns the modified array

Construct a circular line or polygon. A circle in RethinkDB is a polygon or line approximating a circle of a given radius around a given center, consisting of a specified number of vertices (default 32)

Convert a value of one type into another

When called with values, returns true if a sequence contains all the specified values. When called with predicate functions, returns true if for each predicate there exists at least one element of the stream where that predicate returns true

Counts the number of elements in a sequence. If called with a value, counts the number of times that value occurs in the sequence. If called with a predicate function, counts the number of elements in the sequence where that function returns true

Return a new time object only based on the day, month and year (ie. the same day at 00:00)

Return the day of a time object as a number between 1 and 31

Return the day of week of a time object as a number between 1 and 7 (following ISO 8601 standard)

Return the day of the year of a time object as a number between 1 and 366 (following ISO 8601 standard)

Reference a database

Create a database. A RethinkDB database is a collection of tables, similar to relational databases

Drop a database. The database, all its tables, and corresponding data will be deleted

List all database names in the system. The result is a list of strings

Handle non-existence errors. Tries to evaluate and return its first argument. If an error related to the absence of a value is thrown in the process, or if its first argument returns nil, returns its second argument. (Alternatively, the second argument may be a function which will be called with either the text of the non-existence error or nil.)

Delete one or more documents from a table

Remove one or more elements from an array at a given index. Returns the modified array

Remove the elements of one array from another array

Compute the distance between a point and another geometry object. At least one of the geometry objects specified must be a point

Removes duplicates from elements in a sequence

Divide a list of numbers. Left associative

Divide two numbers

Call an anonymous function using return values from other ReQL commands or queries as arguments

Convert a string to all down case

Return if a time is between two other times (by default, inclusive for the start, exclusive for the end)

Create a time object based on seconds since epoch. The first argument is a double and will be rounded to three decimal places (millisecond-precision)

Test if all values in a list are equal

Test if two values are equal

Join tables using a field on the left-hand sequence matching primary keys or secondary indexes on the right-hand table. eq_join is more efficient than other ReQL join types, and operates much faster. Documents in the result set consist of pairs of left-hand and right-hand documents, matched when the field on the left-hand side exists and is non-null and an entry with that field’s value exists in the specified index on the right-hand side

Throw a runtime error

Convert a Line object into a Polygon object. If the last point does not specify the same coordinates as the first point, polygon will close the polygon by connecting them

Get all the documents for which the given predicate is true

Concatenate one or more elements into a single sequence using a mapping function

Rounds the given value down, returning the largest integer value less than or equal to the given value (the value’s floor)

Loop over a sequence, evaluating the given write query for each element

Test if all values in a list are greater than or equal to the next. Left associative

Test if one value is greater than or equal to the other

Convert a GeoJSON object to a ReQL geometry object

Get a document by primary key

Get all documents where the given value matches the value of the requested index

Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it

Get all documents where the given geometry object intersects the geometry object of the requested geospatial index

Get all documents where the specified geospatial index is within a certain distance of the specified point (default 100 kilometers)

Takes a stream and partitions it into multiple groups based on the fields or functions provided

Test if all values in a list are greater than the next. Left associative

Test if one value is greater than the other

Test if an object has one or more fields. An object has a field if it has that key and the key has a non-null value. For instance, the object {‘a’: 1,’b’: 2,’c’: null} has the fields a and b

Return the hour in a time object as a number between 0 and 23

Retrieve data from the specified URL over HTTP. The return type depends on the result_format option, which checks the Content-Type of the response by default

Return a new time object with a different timezone. While the time stays the same, the results returned by methods such as hours() will change since they take the timezone into account. The timezone argument has to be of the ISO 8601 format

Tests whether a geometry object is completely contained within another. When applied to a sequence of geometry objects, includes acts as a filter, returning a sequence of objects from the sequence that include the argument

Create a new secondary index on a table. Secondary indexes improve the speed of many read queries at the slight cost of increased storage space and decreased write performance. For more information about secondary indexes, read the article “Using secondary indexes in RethinkDB.”

Delete a previously created secondary index of this table

List all the secondary indexes of this table

Rename an existing secondary index on a table. If the optional argument overwrite is specified as true, a previously existing index with the new name will be deleted and the index will be renamed. If overwrite is false (the default) an error will be raised if the new index name already exists

Get the status of the specified indexes on this table, or the status of all indexes on this table if no indexes are specified

Wait for the specified indexes on this table to be ready, or for all indexes on this table to be ready if no indexes are specified

Get information about a ReQL value

Returns an inner join of two sequences. The returned sequence represents an intersection of the left-hand sequence and the right-hand sequence: each row of the left-hand sequence will be compared with each row of the right-hand sequence to find all pairs of rows which satisfy the predicate. Each matched pair of rows of both sequences are combined into a result row. In most cases, you will want to follow the join with zip to combine the left and right results

Insert documents into a table. Accepts a single document or an array of documents

Insert a value in to an array at a given index. Returns the modified array

Tests whether two geometry objects intersect with one another. When applied to a sequence of geometry objects, intersects acts as a filter, returning a sequence of objects from the sequence that intersect with the argument

Test if a sequence is empty

Create a time object based on an ISO 8601 date-time string (e.g. ‘2013-01-01T01:01:01+00:00’). We support all valid ISO 8601 formats except for week dates. If you pass an ISO 8601 date-time without a time zone, you must specify the time zone with the default_timezone argument

Create a javascript expression

Parse a JSON string on the server

Return an array containing all of the object’s keys

Test if all values in a list are less than or equal to the next. Left associative

Test if one value is less than or equal to the other

End the sequence after the given number of elements

Construct a geometry object of type Line. The line can be specified in one of two ways:

Replace an object in a field instead of merging it with an existing object in a merge or update operation

Test if all values in a list are less than the next. Left associative

Test if one value is less than the other

Transform each element of one or more sequences by applying a mapping function to them. If map is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence

Checks a string for matches

Finds the maximum element of a sequence. The max command can be called with:

Merge two or more objects together to construct a new object with properties from all. When there is a conflict between field names, preference is given to fields in the rightmost object in the argument list

Finds the minimum element of a sequence. The min command can be called with:

Return the minute in a time object as a number between 0 and 59

Find the remainder when dividing two numbers

Return the month of a time object as a number between 1 and 12

Multiply multiple values

Multiply two numbers, or make a periodic array

Test if all values in a list are not equal

Test if two values are not equal

Compute the logical inverse (not) of an expression

Return a time object representing the current time in UTC. The command now() is computed once when the server receives the query, so multiple instances of r.now() will always return the same time inside a query

Get the nth element of a sequence, counting from zero. If the argument is negative, count from the last element

Creates an object from a list of key-value pairs, where the keys must be strings. r.object(A, B, C, D) is equivalent to r.expr([[A, B], [C, D]]).coerce_to(‘OBJECT’)

Get the indexes of an element in a sequence. If the argument is a predicate, get the indexes of all elements matching it

Compute the logical “or” of all values in a list

Compute the logical “or” of two values

Sort the sequence by document values of the given key(s). To specify the ordering, wrap the attribute with either r.asc or r.desc (defaults to ascending)

Returns a left outer join of two sequences. The returned sequence represents a union of the left-hand sequence and the right-hand sequence: all documents in the left-hand sequence will be returned, each matched with a document in the right-hand sequence if one satisfies the predicate condition. In most cases, you will want to follow the join with zip to combine the left and right results

Plucks out one or more attributes from either an object or a sequence of objects (projection)

Construct a geometry object of type Point. The point is specified by two floating point numbers, the longitude (−180 to 180) and latitude (−90 to 90) of the point on a perfect sphere

Construct a geometry object of type Polygon. The Polygon can be specified in one of two ways:

Use polygon2 to “punch out” a hole in polygon1. polygon2 must be completely contained within polygon1 and must have no holes itself (it must not be the output of polygon_sub itself)

Prepend a value to an array

Generate a random float between 0 and 1

Generate a random value in the range [0,upper). If upper is an integer then the random value will be an integer. If upper is a float it will be a float

Generate a random value in the range [lower,upper). If either arg is an integer then the random value will be an interger. If one of them is a float it will be a float

Generate a stream of sequential integers in a specified range

Produce a single value from a sequence through repeated application of a reduction function

Replace documents in a table. Accepts a JSON document or a ReQL expression, and replaces the original document with the new one. The new document must have the same primary key as the original document

Rounds the given value to the nearest whole integer

Select a given number of elements from a sequence with uniform random distribution. Selection is done without replacement

Return the seconds in a time object as a number between 0 and 59.999 (double precision)

Remove the elements of one array from another and return them as a set (an array with distinct values)

Add a value to an array and return it as a set (an array with distinct values)

Intersect two arrays returning values that occur in both of them as a set (an array with distinct values)

Add a several values to an array and return it as a set (an array with distinct values)

Skip a number of elements from the head of the sequence

Return the elements of a sequence within the specified range

Insert several values in to an array at a given index. Returns the modified array

Split a string on whitespace

Split a string on separator

Split a string with a given separator into max_result segments

Subtract multiple values. Left associative

Subtract two numbers

Sums all the elements of a sequence. If called with a field name, sums all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and sums the results, skipping elements of the sequence where that function returns nil or a non-existence error

sync ensures that writes on a given table are written to permanent storage. Queries that specify soft durability (durability=’soft’) do not give such guarantees, so sync can be used to ensure the state of these queries. A call to sync does not return until all previous writes to the table are persisted

Return all documents in a table. Other commands may be chained after table to return a subset of documents (such as get and filter) or perform further processing

Create a table. A RethinkDB table is a collection of JSON documents

Drop a table. The table and all its data will be deleted

List all table names in a database. The result is a list of strings

Create a time object for a specific time

Return the number of seconds elapsed since the beginning of the day stored in the time object

Return the timezone of the time object

Convert a time object to its epoch time

Convert a ReQL geometry object to a GeoJSON object

Convert a time object to a string in ISO 8601 format

Serialize to JSON string on the server

Gets the type of a value

Takes a grouped stream or grouped data and turns it into an array of objects representing the groups. Any commands chained after ungroup will operate on this array, rather than operating on each group individually. This is useful if you want to e.g. order the groups by the value of their reduction

Concatenate two or more sequences

Convert a string to all upper case

Update JSON documents in a table. Accepts a JSON document, a ReQL expression, or a combination of the two

Return a UUID (universally unique identifier), a string that can be used as a unique ID

Return an array containing all of the object’s values

Plucks one or more attributes from a sequence of objects, filtering out any objects in the sequence that do not have the specified fields. Functionally, this is identical to has_fields followed by pluck on a sequence

The opposite of pluck; takes an object or a sequence of objects, and returns them with the specified paths removed

Return the year of a time object

Used to ‘zip’ up the result of a join by merging the ‘right’ fields into ‘left’ fields of each member of the sequence

Types

reql_array :: [term] | t
reql_binary ::
  %RethinkDB.Pseudotypes.Binary{data: term} |
  binary |
  t
reql_bool :: boolean | t
reql_datum :: term
reql_func0 :: (() -> term) | t
reql_func1 :: (term -> term) | t
reql_func2 :: (term, term -> term) | t
reql_geo_line ::
  %RethinkDB.Pseudotypes.Geometry.Line{coordinates: term} |
  t
reql_geo_point ::
  %RethinkDB.Pseudotypes.Geometry.Point{coordinates: term} |
  {reql_number, reql_number} |
  t
reql_geo_polygon ::
  %RethinkDB.Pseudotypes.Geometry.Polygon{inner_coordinates: term, outer_coordinates: term} |
  t
reql_number :: integer | float | t
reql_obj :: %{} | t
reql_opts :: %{}
reql_time ::
  %RethinkDB.Pseudotypes.Time{epoch_time: term, timezone: term} |
  t
t :: %RethinkDB.Q{query: term}

Functions

add(args)

Specs

add([RethinkDB.Q.reql_number | RethinkDB.Q.reql_string | RethinkDB.Q.reql_array]) :: RethinkDB.Q.t

Add multiple values.

iex> add([1, 2]) |> run conn
%RethinkDB.Record{data: 3}

iex> add(["hello", " world"]) |> run
%RethinkDB.Record{data: "hello world"}
add(left, right)

Specs

add(RethinkDB.Q.reql_number | RethinkDB.Q.reql_string, RethinkDB.Q.reql_number | RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Sum two numbers, concatenate two strings, or concatenate 2 arrays.

iex> add(1, 2) |> run conn
%RethinkDB.Record{data: 3}

iex> add("hello", " world") |> run conn
%RethinkDB.Record{data: "hello world"}

iex> add([1,2], [3,4]) |> run conn
%RethinkDB.Record{data: [1,2,3,4]}
and_r(args)

Specs

and_r([RethinkDB.Q.reql_bool]) :: RethinkDB.Q.t

Compute the logical “and” of all values in a list.

iex> and_r([true, true, true]) |> run conn
%RethinkDB.Record{data: true}

iex> and_r([false, true, true]) |> run conn
%RethinkDB.Record{data: false}
and_r(left, right)

Specs

and_r(RethinkDB.Q.reql_bool, RethinkDB.Q.reql_bool) :: RethinkDB.Q.t

Compute the logical “and” of two values.

iex> and(true, true) |> run conn
%RethinkDB.Record{data: true}

iex> and(false, true) |> run conn
%RethinkDB.Record{data: false}
append(left, right)

Specs

append(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Append a value to an array.

args(arg)

Specs

args(RethinkDB.Q.reql_array) :: RethinkDB.Q.t

args is a special term that’s used to splice an array of arguments into another term. This is useful when you want to call a variadic term such as get_all with a set of arguments produced at runtime.

This is analogous to Elixir’s apply.

asc(key)
avg(arg)

Specs

avg(RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns None or a non-existence error.

Produces a non-existence error when called on an empty sequence. You can handle this case with default.

avg(left, right)

Specs

avg(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
between(arg1, arg2, arg3)

Specs

between(RethinkDB.Q.reql_array, RethinkDB.Q.t, RethinkDB.Q.t) :: RethinkDB.Q.t

Get all documents between two keys. Accepts three optional arguments: index, left_bound, and right_bound. If index is set to the name of a secondary index, between will return all documents where that index’s value is in the specified range (it uses the primary key by default). left_bound or right_bound may be set to open or closed to indicate whether or not to include that endpoint of the range (by default, left_bound is closed and right_bound is open).

between(arg1, arg2, arg3, opts)
binary(data)

Specs

binary(RethinkDB.Q.reql_binary) :: RethinkDB.Q.t

Encapsulate binary data within a query.

Only a limited subset of ReQL commands may be chained after binary:

  • coerce_to can coerce binary objects to string types
  • count will return the number of bytes in the object
  • slice will treat bytes like array indexes (i.e., slice(10,20) will return bytes
  • 10–19)
  • type_of returns PTYPE
  • info will return information on a binary object.
bracket(obj, key)
branch(arg1, arg2, arg3)

Specs

branch(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

If the test expression returns False or None, the false_branch will be evaluated. Otherwise, the true_branch will be evaluated.

The branch command is effectively an if renamed due to language constraints.

ceil(arg)

Specs

ceil(RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Rounds the given value up, returning the smallest integer value greater than or equal to the given value (the value’s ceiling).

change_at(arg1, arg2, arg3)

Specs

change_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Change a value in an array at a given index. Returns the modified array.

changes(arg)
changes(arg, opts)
circle(left, right)

Construct a circular line or polygon. A circle in RethinkDB is a polygon or line approximating a circle of a given radius around a given center, consisting of a specified number of vertices (default 32).

The center may be specified either by two floating point numbers, the latitude (−90 to 90) and longitude (−180 to 180) of the point on a perfect sphere (see Geospatial support for more information on ReQL’s coordinate system), or by a point object. The radius is a floating point number whose units are meters by default, although that may be changed with the unit argument.

Optional arguments available with circle are:

  • num_vertices: the number of vertices in the polygon or line. Defaults to 32.
  • geo_system: the reference ellipsoid to use for geographic coordinates. Possible values are WGS84 (the default), a common standard for Earth’s geometry, or unit_sphere, a perfect sphere of 1 meter radius.
  • unit: Unit for the radius distance. Possible values are m (meter, the default), km (kilometer), mi (international mile), nm (nautical mile), ft (international foot).
  • fill: if true (the default) the circle is filled, creating a polygon; if false the circle is unfilled (creating a line).
circle(left, right, opts)

Specs

circle(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_number, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
coerce_to(left, right)

Specs

coerce_to(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Convert a value of one type into another.

  • a sequence, selection or object can be coerced to an array
  • an array of key-value pairs can be coerced to an object
  • a string can be coerced to a number
  • any datum (single value) can be coerced to a string
  • a binary object can be coerced to a string and vice-versa
concat_map(left, right)
config(arg)

Specs

config(RethinkDB.Q.reql_term) :: RethinkDB.Q.t
contains(seq, args)

Specs

contains(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_func1 | RethinkDB.Q.t) :: RethinkDB.Q.t

When called with values, returns true if a sequence contains all the specified values. When called with predicate functions, returns true if for each predicate there exists at least one element of the stream where that predicate returns true.

count(arg)

Specs

count(RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Counts the number of elements in a sequence. If called with a value, counts the number of times that value occurs in the sequence. If called with a predicate function, counts the number of elements in the sequence where that function returns true.

If count is called on a binary object, it will return the size of the object in bytes.

count(left, right)

Specs

count(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
date(arg)

Specs

date(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return a new time object only based on the day, month and year (ie. the same day at 00:00).

day(arg)

Specs

day(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the day of a time object as a number between 1 and 31.

day_of_week(arg)

Specs

day_of_week(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the day of week of a time object as a number between 1 and 7 (following ISO 8601 standard).

day_of_year(arg)

Specs

day_of_year(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the day of the year of a time object as a number between 1 and 366 (following ISO 8601 standard).

db(arg)

Specs

db(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Reference a database.

db_create(arg)

Specs

db_create(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Create a database. A RethinkDB database is a collection of tables, similar to relational databases.

If successful, the command returns an object with two fields:

  • dbs_created: always 1.
  • config_changes: a list containing one object with two fields, old_val and new_val:
  • old_val: always null.
  • new_val: the database’s new config value.

If a database with the same name already exists, the command throws RqlRuntimeError.

Note: Only alphanumeric characters and underscores are valid for the database name.

db_drop(arg)

Specs

db_drop(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Drop a database. The database, all its tables, and corresponding data will be deleted.

If successful, the command returns an object with two fields:

  • dbs_dropped: always 1.
  • tables_dropped: the number of tables in the dropped database.
  • config_changes: a list containing one two-field object, old_val and new_val:
  • old_val: the database’s original config value.
  • new_val: always None.

If the given database does not exist, the command throws RqlRuntimeError.

db_list()

Specs

db_list :: RethinkDB.Q.t

List all database names in the system. The result is a list of strings.

default(left, right)

Specs

default(RethinkDB.Q.t, RethinkDB.Q.t) :: RethinkDB.Q.t

Handle non-existence errors. Tries to evaluate and return its first argument. If an error related to the absence of a value is thrown in the process, or if its first argument returns nil, returns its second argument. (Alternatively, the second argument may be a function which will be called with either the text of the non-existence error or nil.)

delete(arg)

Specs

delete(RethinkDB.Q.t) :: RethinkDB.Q.t

Delete one or more documents from a table.

The optional arguments are:

  • durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode RethinkDB will acknowledge the write immediately after receiving it, but before the write has been committed to disk.
  • return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.

Delete returns an object that contains the following attributes:

  • deleted: the number of documents that were deleted.
  • skipped: the number of documents that were skipped. For example, if you attempt to delete a batch of documents, and another concurrent query deletes some of those documents first, they will be counted as skipped.
  • errors: the number of errors encountered while performing the delete.
  • first_error: If errors were encountered, contains the text of the first error. inserted, replaced, and unchanged: all 0 for a delete operation.
  • changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the delete operation. Each object will have
  • two keys: {“new_val”: None, “old_val”: }.
delete(arg, opts)
delete_at(left, right)

Remove one or more elements from an array at a given index. Returns the modified array.

delete_at(arg1, arg2, arg3)

Specs

delete_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
desc(key)
difference(left, right)

Specs

difference(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Remove the elements of one array from another array.

distance(left, right)

Compute the distance between a point and another geometry object. At least one of the geometry objects specified must be a point.

Optional arguments available with distance are:

  • geo_system: the reference ellipsoid to use for geographic coordinates. Possible values are WGS84 (the default), a common standard for Earth’s geometry, or unit_sphere, a perfect sphere of 1 meter radius.
  • unit: Unit to return the distance in. Possible values are m (meter, the default), km (kilometer), mi (international mile), nm (nautical mile), ft (international foot).

If one of the objects is a polygon or a line, the point will be projected onto the line or polygon assuming a perfect sphere model before the distance is computed (using the model specified with geo_system). As a consequence, if the polygon or line is extremely large compared to Earth’s radius and the distance is being computed with the default WGS84 model, the results of distance should be considered approximate due to the deviation between the ellipsoid and spherical models.

distance(left, right, opts)

Specs

distance(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
distinct(arg)

Removes duplicates from elements in a sequence.

The distinct command can be called on any sequence, a table, or called on a table with an index.

distinct(arg, opts)

Specs

distinct(RethinkDB.Q.reql_array, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
divide(args)

Specs

divide([RethinkDB.Q.reql_number]) :: RethinkDB.Q.t

Divide a list of numbers. Left associative.

iex> divide([12, 2, 3]) |> run conn
%RethinkDB.Record{data: 2}
divide(left, right)

Specs

divide(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Divide two numbers.

iex> divide(12, 4) |> run conn
%RethinkDB.Record{data: 3}
do_binary(data)
do_r(arg)

Call an anonymous function using return values from other ReQL commands or queries as arguments.

The last argument to do (or, in some forms, the only argument) is an expression or an anonymous function which receives values from either the previous arguments or from prefixed commands chained before do. The do command is essentially a single-element map, letting you map a function over just one document. This allows you to bind a query result to a local variable within the scope of do, letting you compute the result just once and reuse it in a complex expression or in a series of ReQL commands.

Arguments passed to the do function must be basic data types, and cannot be streams or selections. (Read about ReQL data types.) While the arguments will all be evaluated before the function is executed, they may be evaluated in any order, so their values should not be dependent on one another. The type of do’s result is the type of the value returned from the function or last expression.

do_r(data, f)

Specs

do_r(RethinkDB.Q.reql_datum | RethinkDB.Q.reql_func0, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
downcase(arg)

Specs

downcase(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Convert a string to all down case.

iex> "Hi" |> downcase |> run conn
%RethinkDB.Record{data: "hi"}
during(arg1, arg2, arg3)

Specs

during(RethinkDB.Q.reql_time, RethinkDB.Q.reql_time, RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return if a time is between two other times (by default, inclusive for the start, exclusive for the end).

during(arg1, arg2, arg3, opts)
epoch_time(arg)

Specs

epoch_time(reql_number) :: RethinkDB.Q.t

Create a time object based on seconds since epoch. The first argument is a double and will be rounded to three decimal places (millisecond-precision).

eq(args)

Specs

eq([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t

Test if all values in a list are equal.

iex> eq([2, 2, 2]) |> run conn
%RethinkDB.Record{data: true}

iex> eq([2, 1, 2]) |> run conn
%RethinkDB.Record{data: false}
eq(left, right)

Specs

eq(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Test if two values are equal.

iex> eq(1,1) |> run conn
%RethinkDB.Record{data: true}

iex> eq(1, 2) |> run conn
%RethinkDB.Record{data: false}
eq_join(arg1, arg2, arg3)

Join tables using a field on the left-hand sequence matching primary keys or secondary indexes on the right-hand table. eq_join is more efficient than other ReQL join types, and operates much faster. Documents in the result set consist of pairs of left-hand and right-hand documents, matched when the field on the left-hand side exists and is non-null and an entry with that field’s value exists in the specified index on the right-hand side.

The result set of eq_join is a stream or array of objects. Each object in the returned set will be an object of the form `{ left: <left-document>, right: <right-document> }`, where the values of left and right will be the joined documents. Use the zip command to merge the left and right fields together.

iex> table("people") |> eq_join(
    "id", table("phone_numbers"), %{index: "person_id"}
  ) |> run
eq_join(arg1, arg2, arg3, opts)

Specs

eq_join(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string, RethinkDB.Q.reql_array, %{}) :: RethinkDB.Q.t
error(arg)

Specs

error(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Throw a runtime error.

fill(arg)

Specs

fill(RethinkDB.Q.reql_line) :: RethinkDB.Q.t

Convert a Line object into a Polygon object. If the last point does not specify the same coordinates as the first point, polygon will close the polygon by connecting them.

filter(left, right)

Specs

filter(RethinkDB.Q.reql_array, RethinkDB.Q.t) :: RethinkDB.Q.t

Get all the documents for which the given predicate is true.

filter can be called on a sequence, selection, or a field containing an array of elements. The return type is the same as the type on which the function was called on.

The body of every filter is wrapped in an implicit .default(False), which means that if a non-existence errors is thrown (when you try to access a field that does not exist in a document), RethinkDB will just ignore the document. The default value can be changed by passing the named argument default. Setting this optional argument to r.error() will cause any non-existence errors to return a RqlRuntimeError.

filter(left, right, opts)
flat_map(left, right)

Specs

flat_map(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t

Concatenate one or more elements into a single sequence using a mapping function.

floor(arg)

Specs

floor(RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Rounds the given value down, returning the largest integer value less than or equal to the given value (the value’s floor).

for_each(left, right)

Specs

for_each(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t

Loop over a sequence, evaluating the given write query for each element.

func(f)
ge(args)

Specs

ge([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t

Test if all values in a list are greater than or equal to the next. Left associative.

iex> le([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}

iex> le([10, 4, 4]) |> run conn
%RethinkDB.Record{data: true}
ge(left, right)

Specs

ge(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Test if one value is greater than or equal to the other.

iex> ge(1,1) |> run conn
%RethinkDB.Record{data: true}

iex> ge(2, 1) |> run conn
%RethinkDB.Record{data: true}
geojson(arg)

Specs

geojson(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t

Convert a GeoJSON object to a ReQL geometry object.

RethinkDB only allows conversion of GeoJSON objects which have ReQL equivalents: Point, LineString, and Polygon. MultiPoint, MultiLineString, and MultiPolygon are not supported. (You could, however, store multiple points, lines and polygons in an array and use a geospatial multi index with them.)

Only longitude/latitude coordinates are supported. GeoJSON objects that use Cartesian coordinates, specify an altitude, or specify their own coordinate reference system will be rejected.

get(left, right)

Specs

get(RethinkDB.Q.t, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Get a document by primary key.

If no document exists with that primary key, get will return nil.

get_all(seq, args)

Specs

get_all(RethinkDB.Q.t, RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Get all documents where the given value matches the value of the requested index.

get_all(seq, args, opts)
get_field(left, right)

Specs

get_field(RethinkDB.Q.reql_obj | RethinkDB.Q.reql_array, RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it.

get_intersecting(left, right)

Get all documents where the given geometry object intersects the geometry object of the requested geospatial index.

The index argument is mandatory. This command returns the same results as filter(r.row('index')) |> intersects(geometry). The total number of results is limited to the array size limit which defaults to 100,000, but can be changed with the array_limit option to run.

get_intersecting(left, right, opts)

Specs

get_intersecting(RethinkDB.Q.reql_array, RethinkDB.Q.reql_geo, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
get_nearest(left, right)

Get all documents where the specified geospatial index is within a certain distance of the specified point (default 100 kilometers).

The index argument is mandatory. Optional arguments are:

  • max_results: the maximum number of results to return (default 100).
  • unit: Unit for the distance. Possible values are m (meter, the default), km (kilometer), mi (international mile), nm (nautical mile), ft (international foot).
  • max_dist: the maximum distance from an object to the specified point (default 100 km).
  • geo_system: the reference ellipsoid to use for geographic coordinates. Possible values are WGS84 (the default), a common standard for Earth’s geometry, or unit_sphere, a perfect sphere of 1 meter radius.

The return value will be an array of two-item objects with the keys dist and doc, set to the distance between the specified point and the document (in the units specified with unit, defaulting to meters) and the document itself, respectively.

get_nearest(left, right, opts)

Specs

get_nearest(RethinkDB.Q.reql_array, RethinkDB.Q.reql_geo, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
group(seq, args)

Specs

group(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1 | RethinkDB.Q.reql_string | [RethinkDB.Q.reql_func1 | RethinkDB.Q.reql_string]) :: RethinkDB.Q.t

Takes a stream and partitions it into multiple groups based on the fields or functions provided.

With the multi flag single documents can be assigned to multiple groups, similar to the behavior of multi-indexes. When multi is True and the grouping value is an array, documents will be placed in each group that corresponds to the elements of the array. If the array is empty the row will be ignored.

group(seq, args, opts)
gt(args)

Specs

gt([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t

Test if all values in a list are greater than the next. Left associative.

iex> gt([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}

iex> gt([10, 4, 2]) |> run conn
%RethinkDB.Record{data: true}
gt(left, right)

Specs

gt(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Test if one value is greater than the other.

iex> gt(1,2) |> run conn
%RethinkDB.Record{data: false}

iex> gt(2,1) |> run conn
%RethinkDB.Record{data: true}
has_fields(left, right)

Specs

has_fields(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Test if an object has one or more fields. An object has a field if it has that key and the key has a non-null value. For instance, the object {‘a’: 1,’b’: 2,’c’: null} has the fields a and b.

hours(arg)

Specs

hours(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the hour in a time object as a number between 0 and 23.

http(arg)

Retrieve data from the specified URL over HTTP. The return type depends on the result_format option, which checks the Content-Type of the response by default.

http(arg, opts)

Specs

http(RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
in_timezone(left, right)

Specs

in_timezone(RethinkDB.Q.reql_time, RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Return a new time object with a different timezone. While the time stays the same, the results returned by methods such as hours() will change since they take the timezone into account. The timezone argument has to be of the ISO 8601 format.

includes(left, right)

Specs

includes(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo) :: RethinkDB.Q.t

Tests whether a geometry object is completely contained within another. When applied to a sequence of geometry objects, includes acts as a filter, returning a sequence of objects from the sequence that include the argument.

index_create(left, right)

Create a new secondary index on a table. Secondary indexes improve the speed of many read queries at the slight cost of increased storage space and decreased write performance. For more information about secondary indexes, read the article “Using secondary indexes in RethinkDB.”

RethinkDB supports different types of secondary indexes:

  • Simple indexes based on the value of a single field.
  • Compound indexes based on multiple fields.
  • Multi indexes based on arrays of values.
  • Geospatial indexes based on indexes of geometry objects, created when the geo optional argument is true.
  • Indexes based on arbitrary expressions.

The index_function can be an anonymous function or a binary representation obtained from the function field of index_status.

If successful, create_index will return an object of the form {:created => 1}. If an index by that name already exists on the table, a RqlRuntimeError will be thrown.

index_create(left, right, opts)
index_create(arg1, arg2, arg3, opts)

Specs

index_create(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_func1, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
index_drop(left, right)

Specs

index_drop(RethinkDB.Q.t, RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Delete a previously created secondary index of this table.

index_list(arg)

Specs

index_list(RethinkDB.Q.t) :: RethinkDB.Q.t

List all the secondary indexes of this table.

index_rename(arg1, arg2, arg3)

Rename an existing secondary index on a table. If the optional argument overwrite is specified as true, a previously existing index with the new name will be deleted and the index will be renamed. If overwrite is false (the default) an error will be raised if the new index name already exists.

The return value on success will be an object of the format {:renamed => 1}, or {:renamed => 0} if the old and new names are the same.

An error will be raised if the old index name does not exist, if the new index name is already in use and overwrite is false, or if either the old or new index name are the same as the primary key field name.

index_rename(arg1, arg2, arg3, opts)

Specs

index_rename(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
index_status(arg)

Get the status of the specified indexes on this table, or the status of all indexes on this table if no indexes are specified.

index_status(seq, args)

Specs

index_status(RethinkDB.Q.t, RethinkDB.Q.reql_string | RethinkDB.Q.reql_array) :: RethinkDB.Q.t
index_wait(arg)

Wait for the specified indexes on this table to be ready, or for all indexes on this table to be ready if no indexes are specified.

index_wait(seq, args)

Specs

index_wait(RethinkDB.Q.t, RethinkDB.Q.reql_string | RethinkDB.Q.reql_array) :: RethinkDB.Q.t
info(arg)

Specs

info(RethinkDB.Q.t) :: RethinkDB.Q.t

Get information about a ReQL value.

inner_join(arg1, arg2, arg3)

Specs

inner_join(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array, RethinkDB.Q.reql_func2) :: RethinkDB.Q.t

Returns an inner join of two sequences. The returned sequence represents an intersection of the left-hand sequence and the right-hand sequence: each row of the left-hand sequence will be compared with each row of the right-hand sequence to find all pairs of rows which satisfy the predicate. Each matched pair of rows of both sequences are combined into a result row. In most cases, you will want to follow the join with zip to combine the left and right results.

Note that inner_join is slower and much less efficient than using eqJoin or flat_map with get_all. You should avoid using inner_join in commands when possible.

iex> table("people") |> inner_join(
    table("phone_numbers"), &(eq(&1["id"], &2["person_id"])
  ) |> run
insert(left, right)

Insert documents into a table. Accepts a single document or an array of documents.

The optional arguments are:

  • durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode Rethink_dB will acknowledge the write immediately after receiving and caching it, but before the write has been committed to disk.
  • return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.
  • conflict: Determine handling of inserting documents with the same primary key as existing entries. Possible values are “error”, “replace” or “update”.
  • “error”: Do not insert the new document and record the conflict as an error. This is the default.
  • “replace”: Replace the old document in its entirety with the new one.
  • “update”: Update fields of the old document with fields from the new one.

Insert returns an object that contains the following attributes:

  • inserted: the number of documents successfully inserted.
  • replaced: the number of documents updated when conflict is set to “replace” or “update”.
  • unchanged: the number of documents whose fields are identical to existing documents with the same primary key when conflict is set to “replace” or “update”.
  • errors: the number of errors encountered while performing the insert.
  • first_error: If errors were encountered, contains the text of the first error.
  • deleted and skipped: 0 for an insert operation.
  • generated_keys: a list of generated primary keys for inserted documents whose primary keys were not specified (capped to 100,000).
  • warnings: if the field generated_keys is truncated, you will get the warning “Too many generated keys (), array truncated to 100000.”.
  • changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the insert operation. Each object will have
  • two keys: {“new_val”: , “old_val”: None}.
insert(left, right, opts)

Specs

insert(RethinkDB.Q.t, RethinkDB.Q.reql_obj | RethinkDB.Q.reql_array, %{}) :: RethinkDB.Q.t
insert_at(arg1, arg2, arg3)

Specs

insert_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Insert a value in to an array at a given index. Returns the modified array.

intersects(left, right)

Specs

intersects(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo) :: RethinkDB.Q.t

Tests whether two geometry objects intersect with one another. When applied to a sequence of geometry objects, intersects acts as a filter, returning a sequence of objects from the sequence that intersect with the argument.

is_empty(arg)

Specs

is_empty(RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Test if a sequence is empty.

iso8601(arg)

Specs

iso8601(reql_string) :: RethinkDB.Q.t

Create a time object based on an ISO 8601 date-time string (e.g. ‘2013-01-01T01:01:01+00:00’). We support all valid ISO 8601 formats except for week dates. If you pass an ISO 8601 date-time without a time zone, you must specify the time zone with the default_timezone argument.

iso8601(arg, opts)
js(arg)

Create a javascript expression.

The only opt allowed is timeout.

timeout is the number of seconds before js times out. The default value is 5 seconds.

js(arg, opts)

Specs

js(RethinkDB.Q.reql_string, RethinkDB.Q.opts) :: RethinkDB.Q.t
json(arg)

Specs

json(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Parse a JSON string on the server.

keys(arg)

Specs

keys(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t

Return an array containing all of the object’s keys.

le(args)

Specs

le([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t

Test if all values in a list are less than or equal to the next. Left associative.

iex> le([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}

iex> le([1, 4, 4]) |> run conn
%RethinkDB.Record{data: true}
le(left, right)

Specs

le(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Test if one value is less than or equal to the other.

iex> le(1,1) |> run conn
%RethinkDB.Record{data: true}

iex> le(1, 2) |> run conn
%RethinkDB.Record{data: true}
limit(left, right)

Specs

limit(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

End the sequence after the given number of elements.

line(args)

Specs

line([RethinkDB.Q.reql_geo]) :: RethinkDB.Q.t

Construct a geometry object of type Line. The line can be specified in one of two ways:

  • Two or more two-item arrays, specifying latitude and longitude numbers of the line’s vertices;
  • Two or more Point objects specifying the line’s vertices.
literal(arg)

Specs

literal(RethinkDB.Q.reql_object) :: RethinkDB.Q.t

Replace an object in a field instead of merging it with an existing object in a merge or update operation.

lt(args)

Specs

lt([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t

Test if all values in a list are less than the next. Left associative.

iex> lt([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}

iex> lt([1, 4, 5]) |> run conn
%RethinkDB.Record{data: true}
lt(left, right)

Specs

lt(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Test if one value is less than the other.

iex> lt(2,1) |> run conn
%RethinkDB.Record{data: false}

iex> lt(1, 2) |> run conn
%RethinkDB.Record{data: true}
make_array(array)
map(left, right)

Specs

map(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t

Transform each element of one or more sequences by applying a mapping function to them. If map is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence.

Note that map can only be applied to sequences, not single values. If you wish to apply a function to a single value/selection (including an array), use the do command.

match(string, right)

Specs

match(RethinkDB.Q.reql_string, Regex.t | RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Checks a string for matches.

Example:

iex> "hello world" |> match("hello") |> run conn
iex> "hello world" |> match(~r(hello)) |> run conn
max(arg)

Finds the maximum element of a sequence. The max command can be called with:

  • a field name, to return the element of the sequence with the smallest value in that field;
  • an index, to return the element of the sequence with the smallest value in that index;
  • a function, to apply the function to every element within the sequence and return the element which returns the smallest value from the function, ignoring any elements where the function returns None or produces a non-existence error.

Calling max on an empty sequence will throw a non-existence error; this can be handled using the default command.

max(left, right)

Specs

max(RethinkDB.Q.reql_array, RethinkDB.Q.reql_opts | RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
maxval()
merge(args)
merge(left, right)

Specs

merge(RethinkDB.Q.reql_array, RethinkDB.Q.reql_object | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t

Merge two or more objects together to construct a new object with properties from all. When there is a conflict between field names, preference is given to fields in the rightmost object in the argument list.

min(arg)

Finds the minimum element of a sequence. The min command can be called with:

  • a field name, to return the element of the sequence with the smallest value in that field;
  • an index option, to return the element of the sequence with the smallest value in that index;
  • a function, to apply the function to every element within the sequence and return the element which returns the smallest value from the function, ignoring any elements where the function returns None or produces a non-existence error.

Calling min on an empty sequence will throw a non-existence error; this can be handled using the default command.

min(left, right)

Specs

min(RethinkDB.Q.reql_array, RethinkDB.Q.reql_opts | RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
minutes(arg)

Specs

minutes(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the minute in a time object as a number between 0 and 59.

minval()
mod(left, right)

Specs

mod(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Find the remainder when dividing two numbers.

iex> mod(23, 4) |> run conn
%RethinkDB.Record{data: 3}
month(arg)

Specs

month(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the month of a time object as a number between 1 and 12.

mul(args)

Specs

mul([RethinkDB.Q.reql_number | RethinkDB.Q.reql_array]) :: RethinkDB.Q.t

Multiply multiple values.

iex> mul([2,3,4]) |> run conn
%RethinkDB.Record{data: 24}
mul(left, right)

Specs

mul(RethinkDB.Q.reql_number | RethinkDB.Q.reql_array, RethinkDB.Q.reql_number | RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Multiply two numbers, or make a periodic array.

iex> mul(2,3) |> run conn
%RethinkDB.Record{data: 6}

iex> mul([1,2], 2) |> run conn
%RethinkDB.Record{data: [1,2,1,2]}
ne(args)

Specs

ne([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t

Test if all values in a list are not equal.

iex> ne([2, 2, 2]) |> run conn
%RethinkDB.Record{data: false}

iex> ne([2, 1, 2]) |> run conn
%RethinkDB.Record{data: true}
ne(left, right)

Specs

ne(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Test if two values are not equal.

iex> ne(1,1) |> run conn
%RethinkDB.Record{data: false}

iex> ne(1, 2) |> run conn
%RethinkDB.Record{data: true}
not_r(arg)

Specs

not_r(RethinkDB.Q.reql_bool) :: RethinkDB.Q.t

Compute the logical inverse (not) of an expression.

iex> not(true) |> run conn
%RethinkDB.Record{data: false}
now()

Specs

now :: RethinkDB.Q.t

Return a time object representing the current time in UTC. The command now() is computed once when the server receives the query, so multiple instances of r.now() will always return the same time inside a query.

nth(left, right)

Specs

nth(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Get the nth element of a sequence, counting from zero. If the argument is negative, count from the last element.

object(args)

Specs

object(RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Creates an object from a list of key-value pairs, where the keys must be strings. r.object(A, B, C, D) is equivalent to r.expr([[A, B], [C, D]]).coerce_to(‘OBJECT’).

offsets_of(left, right)

Specs

offsets_of(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Get the indexes of an element in a sequence. If the argument is a predicate, get the indexes of all elements matching it.

or_r(args)

Specs

or_r([RethinkDB.Q.reql_bool]) :: RethinkDB.Q.t

Compute the logical “or” of all values in a list.

iex> or_r([true, true, true]) |> run conn
%RethinkDB.Record{data: true}

iex> or_r([false, true, true]) |> run conn
%RethinkDB.Record{data: false}
or_r(left, right)

Specs

or_r(RethinkDB.Q.reql_bool, RethinkDB.Q.reql_bool) :: RethinkDB.Q.t

Compute the logical “or” of two values.

iex> or_r(true, false) |> run conn
%RethinkDB.Record{data: true}

iex> or_r(false, false) |> run conn
%RethinkDB.Record{data: false}
order_by(arg)

Sort the sequence by document values of the given key(s). To specify the ordering, wrap the attribute with either r.asc or r.desc (defaults to ascending).

Sorting without an index requires the server to hold the sequence in memory, and is limited to 100,000 documents (or the setting of the array_limit option for run). Sorting with an index can be done on arbitrarily large tables, or after a between command using the same index.

order_by(left, opts)

Specs

order_by(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
order_by(left, right, opts)
outer_join(arg1, arg2, arg3)

Specs

outer_join(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array, RethinkDB.Q.reql_func2) :: RethinkDB.Q.t

Returns a left outer join of two sequences. The returned sequence represents a union of the left-hand sequence and the right-hand sequence: all documents in the left-hand sequence will be returned, each matched with a document in the right-hand sequence if one satisfies the predicate condition. In most cases, you will want to follow the join with zip to combine the left and right results.

Note that outer_join is slower and much less efficient than using flat_map with get_all. You should avoid using outer_join in commands when possible.

iex> table("people") |> outer_join(
    table("phone_numbers"), &(eq(&1["id"], &2["person_id"])
  ) |> run
pluck(left, right)

Specs

pluck(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Plucks out one or more attributes from either an object or a sequence of objects (projection).

point(arg)

Specs

point(RethinkDB.Q.reql_geo) :: RethinkDB.Q.t

Construct a geometry object of type Point. The point is specified by two floating point numbers, the longitude (−180 to 180) and latitude (−90 to 90) of the point on a perfect sphere.

point(left, right)
polygon(args)

Specs

polygon([RethinkDB.Q.reql_geo]) :: RethinkDB.Q.t

Construct a geometry object of type Polygon. The Polygon can be specified in one of two ways:

Three or more two-item arrays, specifying latitude and longitude numbers of the polygon’s vertices;

  • Three or more Point objects specifying the polygon’s vertices.
  • Longitude (−180 to 180) and latitude (−90 to 90) of vertices are plotted on a perfect sphere. See Geospatial support for more information on ReQL’s coordinate system.

If the last point does not specify the same coordinates as the first point, polygon will close the polygon by connecting them. You cannot directly construct a polygon with holes in it using polygon, but you can use polygon_sub to use a second polygon within the interior of the first to define a hole.

polygon_sub(left, right)

Specs

polygon_sub(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo) :: RethinkDB.Q.t

Use polygon2 to “punch out” a hole in polygon1. polygon2 must be completely contained within polygon1 and must have no holes itself (it must not be the output of polygon_sub itself).

prepend(left, right)

Specs

prepend(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Prepend a value to an array.

random()

Specs

random :: RethinkDB.Q.t

Generate a random float between 0 and 1.

iex> random |> run conn
%RethinkDB.Record{data: 0.43}
random(upper)

Specs

random(RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Generate a random value in the range [0,upper). If upper is an integer then the random value will be an integer. If upper is a float it will be a float.

iex> random(5) |> run conn
%RethinkDB.Record{data: 3}

iex> random(5.0) |> run conn
%RethinkDB.Record{data: 3.7}
random(arg, opts)

Specs

random(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Generate a random value in the range [lower,upper). If either arg is an integer then the random value will be an interger. If one of them is a float it will be a float.

iex> random(5, 10) |> run conn
%RethinkDB.Record{data: 8}

iex> random(5.0, 15.0,) |> run conn
%RethinkDB.Record{data: 8.34}
random(left, right, opts)
range()

Generate a stream of sequential integers in a specified range.

range takes 0, 1 or 2 arguments:

  • With no arguments, range returns an “infinite” stream from 0 up to and including the maximum integer value;
  • With one argument, range returns a stream from 0 up to but not including the end value;
  • With two arguments, range returns a stream from the start value up to but not including the end value.
range(arg)
range(left, right)

Specs

range(RethinkDB.Q.reql_number, RethinkDB.Q.req_number) :: RethinkDB.Q.t
rebalance(arg)

Specs

rebalance(RethinkDB.Q.reql_term) :: RethinkDB.Q.t
reconfigure(arg)
reconfigure(arg, opts)

Specs

reconfigure(RethinkDB.Q.reql_term, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
reduce(left, right)

Specs

reduce(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func2) :: RethinkDB.Q.t

Produce a single value from a sequence through repeated application of a reduction function.

The reduction function can be called on:

  • two elements of the sequence
  • one element of the sequence and one result of a previous reduction
  • two results of previous reductions

The reduction function can be called on the results of two previous reductions because the reduce command is distributed and parallelized across shards and CPU cores. A common mistaken when using the reduce command is to suppose that the reduction is executed from left to right.

replace(left, right)

Replace documents in a table. Accepts a JSON document or a ReQL expression, and replaces the original document with the new one. The new document must have the same primary key as the original document.

The optional arguments are:

  • durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode RethinkDB will acknowledge the write immediately after receiving it, but before the write has been committed to disk.
  • return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.
  • non_atomic: if set to True, executes the replacement and distributes the result to replicas in a non-atomic fashion. This flag is required to perform non-deterministic updates, such as those that require reading data from another table.

Replace returns an object that contains the following attributes:

  • replaced: the number of documents that were replaced
  • unchanged: the number of documents that would have been modified, except that the new value was the same as the old value
  • inserted: the number of new documents added. You can have new documents inserted if you do a point-replace on a key that isn’t in the table or you do a replace on a selection and one of the documents you are replacing has been deleted
  • deleted: the number of deleted documents when doing a replace with None
  • errors: the number of errors encountered while performing the replace.
  • first_error: If errors were encountered, contains the text of the first error.
  • skipped: 0 for a replace operation
  • changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the replace operation. Each object will have
  • two keys: {“new_val”: , “old_val”: }.
replace(left, right, opts)

Specs

replace(RethinkDB.Q.t, RethinkDB.Q.reql_obj, %{}) :: RethinkDB.Q.t
round_r(arg)

Specs

round_r(RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Rounds the given value to the nearest whole integer.

For example, values of 1.0 up to but not including 1.5 will return 1.0, similar to floor; values of 1.5 up to 2.0 will return 2.0, similar to ceil.

sample(left, right)

Specs

sample(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Select a given number of elements from a sequence with uniform random distribution. Selection is done without replacement.

If the sequence has less than the requested number of elements (i.e., calling sample(10) on a sequence with only five elements), sample will return the entire sequence in a random order.

seconds(arg)

Specs

seconds(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the seconds in a time object as a number between 0 and 59.999 (double precision).

set_difference(left, right)

Specs

set_difference(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Remove the elements of one array from another and return them as a set (an array with distinct values).

set_insert(left, right)

Specs

set_insert(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Add a value to an array and return it as a set (an array with distinct values).

set_intersection(left, right)

Specs

set_intersection(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Intersect two arrays returning values that occur in both of them as a set (an array with distinct values).

set_union(left, right)

Specs

set_union(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Add a several values to an array and return it as a set (an array with distinct values).

skip(left, right)

Specs

skip(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Skip a number of elements from the head of the sequence.

slice(arg1, arg2, arg3)

Specs

slice(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Return the elements of a sequence within the specified range.

slice(arg1, arg2, arg3, opts)
splice_at(arg1, arg2, arg3)

Specs

splice_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Insert several values in to an array at a given index. Returns the modified array.

split(arg)

Specs

split(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Split a string on whitespace.

iex> "abracadabra" |> split |> run conn
%RethinkDB.Record{data: ["abracadabra"]}
split(left, right)

Specs

split(RethinkDB.Q.reql_string, RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Split a string on separator.

iex> "abra-cadabra" |> split("-") |> run conn
%RethinkDB.Record{data: ["abra", "cadabra"]}
split(arg1, arg2, arg3)

Specs

split(RethinkDB.Q.reql_string, RethinkDB.Q.reql_string | nil, integer) :: RethinkDB.Q.t

Split a string with a given separator into max_result segments.

iex> "a-bra-ca-da-bra" |> split("-", 2) |> run conn
%RethinkDB.Record{data: ["a", "bra", "ca-da-bra"]}
status(arg)

Specs

status(RethinkDB.Q.reql_term) :: RethinkDB.Q.t
sub(args)

Specs

sub([RethinkDB.Q.reql_number]) :: RethinkDB.Q.t

Subtract multiple values. Left associative.

iex> sub([9, 1, 2]) |> run conn
%RethinkDB.Record{data: 6}
sub(left, right)

Specs

sub(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t

Subtract two numbers.

iex> sub(1, 2) |> run conn
%RethinkDB.Record{data: -1}
sum(arg)

Specs

sum(RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Sums all the elements of a sequence. If called with a field name, sums all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and sums the results, skipping elements of the sequence where that function returns nil or a non-existence error.

Returns 0 when called on an empty sequence.

sum(left, right)

Specs

sum(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
sync(arg)

Specs

sync(RethinkDB.Q.t) :: RethinkDB.Q.t

sync ensures that writes on a given table are written to permanent storage. Queries that specify soft durability (durability=’soft’) do not give such guarantees, so sync can be used to ensure the state of these queries. A call to sync does not return until all previous writes to the table are persisted.

If successful, the operation returns an object: {“synced”: 1}.

table(arg)

Return all documents in a table. Other commands may be chained after table to return a subset of documents (such as get and filter) or perform further processing.

There are two optional arguments.

  • useOutdated: if true, this allows potentially out-of-date data to be returned, with potentially faster reads. It also allows you to perform reads from a secondary replica if a primary has failed. Default false.
  • identifierFormat: possible values are name and uuid, with a default of name. If set to uuid, then system tables will refer to servers, databases and tables by UUID rather than name. (This only has an effect when used with system tables.)
table(arg, opts)

Specs

table(RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
table(left, right, opts)

Specs

table(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
table_create(arg)

Create a table. A RethinkDB table is a collection of JSON documents.

If successful, the command returns an object with two fields:

  • tables_created: always 1.
  • config_changes: a list containing one two-field object, old_val and new_val:
  • old_val: always nil.
  • new_val: the table’s new config value.

If a table with the same name already exists, the command throws RqlRuntimeError.

Note: Only alphanumeric characters and underscores are valid for the table name.

When creating a table you can specify the following options:

  • primary_key: the name of the primary key. The default primary key is id.
  • durability: if set to soft, writes will be acknowledged by the server immediately and flushed to disk in the background. The default is hard: acknowledgment of writes happens after data has been written to disk.
  • shards: the number of shards, an integer from 1-32. Defaults to 1.
  • replicas: either an integer or a mapping object. Defaults to 1. If replicas is an integer, it specifies the number of replicas per shard. Specifying more replicas than there are servers will return an error. If replicas is an object, it specifies key-value pairs of server tags and the number of replicas to assign to those servers: {:tag1 => 2, :tag2 => 4, :tag3 => 2, …}.
  • primary_replica_tag: the primary server specified by its server tag. Required if replicas is an object; the tag must be in the object. This must not be specified if replicas is an integer. The data type of a primary key is usually a string (like a UUID) or a number, but it can also be a time, binary object, boolean or an array. It cannot be an object.
table_create(arg, opts)
table_create(left, right, opts)

Specs

table_create(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
table_drop(arg)

Drop a table. The table and all its data will be deleted.

If successful, the command returns an object with two fields:

  • tables_dropped: always 1.
  • config_changes: a list containing one two-field object, old_val and new_val:
  • old_val: the dropped table’s config value.
  • new_val: always nil.

If the given table does not exist in the database, the command throws RqlRuntimeError.

table_drop(left, right)

Specs

table_drop(RethinkDB.Q.t, RethinkDB.Q.reql_string) :: RethinkDB.Q.t
table_list()

List all table names in a database. The result is a list of strings.

table_list(arg)

Specs

table_list(RethinkDB.Q.t) :: RethinkDB.Q.t
time(year, month, day, timezone)

Specs

time(reql_number, reql_number, reql_number, reql_string) :: RethinkDB.Q.t

Create a time object for a specific time.

A few restrictions exist on the arguments:

  • year is an integer between 1400 and 9,999.
  • month is an integer between 1 and 12.
  • day is an integer between 1 and 31.
  • hour is an integer.
  • minutes is an integer.
  • seconds is a double. Its value will be rounded to three decimal places (millisecond-precision).
  • timezone can be ‘Z’ (for UTC) or a string with the format ±[hh]:[mm].
time(year, month, day, hour, minute, second, timezone)
time_of_day(arg)

Specs

time_of_day(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the number of seconds elapsed since the beginning of the day stored in the time object.

timezone(arg)

Specs

timezone(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the timezone of the time object.

to_epoch_time(arg)

Specs

to_epoch_time(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Convert a time object to its epoch time.

to_geojson(arg)

Specs

to_geojson(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t

Convert a ReQL geometry object to a GeoJSON object.

to_iso8601(arg)

Specs

to_iso8601(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Convert a time object to a string in ISO 8601 format.

to_json(arg)

Specs

to_json(RethinkDB.Q.reql_term) :: RethinkDB.Q.t

Serialize to JSON string on the server.

type_of(arg)

Specs

type_of(RethinkDB.Q.reql_datum) :: RethinkDB.Q.t

Gets the type of a value.

ungroup(arg)

Specs

ungroup(RethinkDB.Q.t) :: RethinkDB.Q.t

Takes a grouped stream or grouped data and turns it into an array of objects representing the groups. Any commands chained after ungroup will operate on this array, rather than operating on each group individually. This is useful if you want to e.g. order the groups by the value of their reduction.

The format of the array returned by ungroup is the same as the default native format of grouped data in the JavaScript driver and data explorer. end

union(left, right)

Specs

union(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Concatenate two or more sequences.

upcase(arg)

Specs

upcase(RethinkDB.Q.reql_string) :: RethinkDB.Q.t

Convert a string to all upper case.

iex> "hi" |> upcase |> run conn
%RethinkDB.Record{data: "HI"}
update(left, right)

Update JSON documents in a table. Accepts a JSON document, a ReQL expression, or a combination of the two.

The optional arguments are:

  • durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode RethinkDB will acknowledge the write immediately after receiving it, but before the write has been committed to disk.
  • return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.
  • non_atomic: if set to True, executes the update and distributes the result to replicas in a non-atomic fashion. This flag is required to perform non-deterministic updates, such as those that require reading data from another table.

Update returns an object that contains the following attributes:

  • replaced: the number of documents that were updated.
  • unchanged: the number of documents that would have been modified except the new value was the same as the old value.
  • skipped: the number of documents that were skipped because the document didn’t exist.
  • errors: the number of errors encountered while performing the update.
  • first_error: If errors were encountered, contains the text of the first error.
  • deleted and inserted: 0 for an update operation.
  • changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the update operation. Each object will have
  • two keys: {“new_val”: , “old_val”: }.
update(left, right, opts)

Specs

update(RethinkDB.Q.t, RethinkDB.Q.reql_obj, %{}) :: RethinkDB.Q.t
uuid()

Return a UUID (universally unique identifier), a string that can be used as a unique ID.

Accepts optionally a string. If given, UUID will be derived from the strings SHA-1 hash.

uuid(arg)

Specs

uuid(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
values(arg)

Specs

values(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t

Return an array containing all of the object’s values.

var(val)
wait(arg)

Specs

wait(RethinkDB.Q.reql_term) :: RethinkDB.Q.t
wait(arg, opts)
with_fields(seq, args)

Specs

with_fields(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Plucks one or more attributes from a sequence of objects, filtering out any objects in the sequence that do not have the specified fields. Functionally, this is identical to has_fields followed by pluck on a sequence.

without(left, right)

Specs

without(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_string) :: RethinkDB.Q.t

The opposite of pluck; takes an object or a sequence of objects, and returns them with the specified paths removed.

year(arg)

Specs

year(RethinkDB.Q.reql_time) :: RethinkDB.Q.t

Return the year of a time object.

zip(arg)

Specs

zip(RethinkDB.Q.reql_array) :: RethinkDB.Q.t

Used to ‘zip’ up the result of a join by merging the ‘right’ fields into ‘left’ fields of each member of the sequence.

iex> table("people") |> eq_join(
    "id", table("phone_numbers"), %{index: "person_id"}
  ) |> zip |> run