ReQL command: delete
Command syntax
table.delete[({:durability => "hard", :return_changes => false, :ignore_write_hook => false})] → object selection.delete[({:durability => "hard", :return_changes => false, :ignore_write_hook => false})] → object singleSelection.delete[({:durability => "hard", :return_changes => false, :ignore_write_hook => false})] → object
Description
Delete one or more documents from a table.
The optional arguments are:
-
durability
: possible values arehard
andsoft
. 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
:-
true
: return achanges
array consisting ofold_val
/new_val
objects describing the changes made, only including the documents actually updated. -
false
: do not return achanges
array (the default). -
"always"
: behave astrue
, but include all documents the command tried to update whether or not the update was successful. (This was the behavior oftrue
pre-2.0.)
-
-
ignore_write_hook
: Iftrue
, and if the user has the config permission, ignores any write hook, which might have prohibited the deletion.
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
, andunchanged
: all 0 for a delete operation.. -
changes
: ifreturn_changes
is set totrue
, this will be an array of objects, one for each objected affected by thedelete
operation. Each object will have two keys:{:new_val => nil, :old_val => <old value>}
.
RethinkDB write operations will only throw exceptions if errors occur before any writes. Other errors will be listed in
first_error
, anderrors
will be set to a non-zero count. To properly handle errors with this term, code must both handle exceptions and check theerrors
return value!
Example: Delete a single document from the table comments
.
r.table("comments").get("7eab9e63-73f1-4f33-8ce4-95cbea626f59").delete.run(conn)
Example: Delete all documents from the table comments
.
r.table("comments").delete.run(conn)
Example: Delete all comments where the field id_post
is 3
.
r.table("comments").filter({:id_post => 3}).delete.run(conn)
Example: Delete a single document from the table comments
and return its value.
r.table("comments").get("7eab9e63-73f1-4f33-8ce4-95cbea626f59").delete(:return_changes => true).run(conn)
The result look like:
{
:deleted => 1,
:errors => 0,
:inserted => 0,
:changes => [
{
:new_val => nil,
:old_val => {
:id => "7eab9e63-73f1-4f33-8ce4-95cbea626f59",
:author => "William",
:comment => "Great post",
:id_post => 3
}
}
],
:replaced => 0,
:skipped => 0,
:unchanged => 0
}
Example: Delete all documents from the table comments
without waiting for the operation to be flushed to disk.
r.table("comments").delete(:durability => "soft").run(conn)
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/ruby/delete/