-
Notifications
You must be signed in to change notification settings - Fork 9
Deleting Documents
There are two ways to delete a document or documents from the database, either by URI or by supplying a query. Both methods require issuing a DELETE request to the /store
endpoint. Deleting a document removes its properties as well. If the document was in any collections that are empty after deleting, those collections are deleted as well.
The response of a DELETE request contains a list of the documents that were deleted and a HTTP status code of 200.
To delete a document by URI, append the URI of the document onto the store endpoint. For example, a DELETE request to the following url will delete the document with a uri of /user/123456.json:
/store?uri=/user/123456.json
If the document doesn't exist in the database, a 404 error is returned.
Instead of supplying the URI of the document to delete, a query can be supplied instead. The queries can take the form of either a string query or structured queries.
/store?stringQuery=id:123456
/store?structuredQuery={"key":"id", "equals": 123456}
The above requests will first find all the documents that match the supplied query. By default the DELETE request will fail if no documents are found (404 response) and will also fail if more than one document is found (400 response). This is in place to try and ensure that only the intended document is deleted. However, if the intention is to delete multiple documents, this can be achieved by specifying bulkDelete=true:
/store?stringQuery=outOfPrint:yes&bulkDelete=true
Use this mode with extreme caution as it can easily delete every document in the database. To perform a bulk delete and limit the number of documents that are deleted, include a limit
parameter:
/store?stringQuery=outOfPrint:yes&bulkDelete=true&limit=1000
That request will delete the first 1000 documents that match the query. This can be useful to avoid an excessively large (and therefore slow) delete transaction.
This needs "Request Details" and "Examples" sections.