Module reql::cmd::changes [−][src]
Expand description
Turn a query into a changefeed, an infinite stream of objects representing changes to the query’s results as they occur
A changefeed may return changes to a table or an individual document
(a “point” changefeed). Commands such as filter
or map
may be used
before the changes
command to transform or filter the output, and
many commands that operate on sequences can be chained after changes
.
If the table becomes unavailable, the changefeed will be disconnected, and a runtime exception will be thrown by the driver.
Changefeed notifications take the form of a two-field object:
{
"old_val": <document before change>,
"new_val": <document after change>
}
When include_types
is true
, there will be three fields:
{
"old_val": <document before change>,
"new_val": <document after change>,
"type": <result type>
}
When a document is deleted, new_val
will be null
; when a document is
inserted, old_val
will be null
.
Certain document transformation commands can be chained before changefeeds. For more information, read the discussion of changefeeds in the “Command language” documentation.
Changefeeds ignore the read_mode
flag to run
, and always behave as if
it is set to single
(i.e., the values they return are in memory on the primary
replica, but have not necessarily been written to disk yet). For more details
read Consistency guarantees.
The server will buffer up to changefeed_queue_size
elements (default 100,000).
If the buffer limit is hit, early changes will be discarded, and the client will
receive an object of the form
{error: "Changefeed cache over array size limit, skipped X elements."}
where X
is the number of elements skipped.
Commands that operate on streams (such as filter or map)
can usually be chained after changes
. However, since the stream produced by
changes
has no ending, commands that need to consume the entire stream before
returning (such as reduce or count) cannot.
Examples
Subscribe to the changes on a table.
Start monitoring the changefeed in one client:
r.table("games").changes(()).run(conn)
As these queries are performed in a second client
r.table("games").insert(json!({"id": 1})).run(conn)
the first client would receive and print the following objects:
{old_val: null, new_val: {id: 1}}
Structs
Options | Optional arguments to |
Enums
Squash | Controls how change notifications are batched |
Traits
Arg |