This week saw the completion of the AQL UPSERT
command. This command will be very helpful in a lot of use cases, including the following:
- ensure that a document exists
- update a document if it exists, otherwise create it
- replace a document if it exists, otherwise create it
The UPSERT
command is executed on the server side and so delivers client applications from issuing a fetch command followed by a separate, conditional UPDATE
or INSERT
command.
The general format of an UPSERT
statement is:
1 2 3 4 5 |
UPSERT search-document INSERT insert-expression UPDATE update-expression IN collection-name |
Jan collected a few example invocations of UPSERT
in his blog.