Back to overview
The DELETE statement can be used to delete records from the database.
DELETE @targets [ WHERE @condition ] [ RETURN [ NONE | BEFORE | AFTER | DIFF | @projections ... ] [ TIMEOUT @duration ] [ PARALLEL ] ;
The following query shows example usage of this statement.
-- Delete all records from a table DELETE person; -- Delete a record with a specific numeric id DELETE person:100; -- Delete a record with a specific string id DELETE person:tobie;
The delete statement supports conditional matching of records using a
WHERE clause. If the expression in the
WHERE clause evaluates to true, then the respective record will be deleted.
-- Update all records which match the condition DELETE city WHERE name = 'London';
By default, the delete statement does not return any data, returning only an empty array if the statement succeeds completely. Specify a
RETURN clause to change the value which is returned for each document that is deleted.
-- Don't return any result (the default) DELETE user WHERE age < 18 RETURN NONE; -- Return the changeset diff DELETE user WHERE interests CONTAINS 'reading' RETURN DIFF; -- Return the record before changes were applied DELETE user WHERE interests CONTAINS 'reading' RETURN BEFORE; -- Return the record after changes were applied DELETE user WHERE interests CONTAINS 'reading' RETURN AFTER;
When processing a large result set with many interconnected records, it is possible to use the
TIMEOUT keywords to specify a timeout duration for the statement. If the statement continues beyond this duration, then the transaction will fail, no records will be deleted from the database, and the statement will return an error.
DELETE person WHERE ->knows->person->(knows WHERE influencer = false) TIMEOUT 5s;