logo
Deletes one document by its id.
πŸ’‘ Deleting an id that does not exist is not an error. You get a normal response with "ack": 0 β€” check that value if you need to know whether anything was actually removed.

Request

method is "deleteDocument".
Field
Type
Required
Description
collection
String
Yes
The collection to delete from.
document_id
String
Yes
The document to delete.
app_id
String
Optional
The app the document belongs to. Defaults to the bot's own app.
reference
String
Optional
Your id for this request. Echoed back in the response.
⚠️ Deletion is permanent and there is no bulk delete β€” one call removes one document. To clear a collection, page through it with listDocuments and delete each id.

Response

deleteDocumentResponse

Field
Type
Returned
Description
method
String
Yes
"deleteDocumentResponse"
collection
String
Yes
Echoed from the request.
document_id
String
Yes
Echoed from the request.
ack
Integer
Yes
Documents removed: 1 on success, 0 if nothing matched.
app_id
String
Yes
Echoed from the request.
reference
String
Optional
Echoed from the request.

SDKs

SDK
Call
Callback
Java
store.deleteDocument(api, collection, documentId, reference);
onDocumentResponse(DocumentResponse response)
JavaScript
store.deleteDocument(api, collection, documentId, reference);
onDocumentResponse(response)
Python
store.delete_document(api, collection, document_id, reference)
on_document_response(self, response)

Example

Request

json
{ "method": "deleteDocument", "collection": "orders", "document_id": "42", "app_id": "90090684293000559", "reference": "123456789" }
java
DocumentStore.getInstance().deleteDocument(api, "orders", "42", "123456789"); // in the callback @Override public void onDocumentResponse(DocumentResponse response) { if (Integer.valueOf(0).equals(response.getAck())) { System.out.println("nothing to delete"); } }
javascript
const store = require('nandbox-bot-api/src/util/DocumentStore') store.deleteDocument(api, 'orders', '42', '123456789') // in the callback nCallBack.onDocumentResponse = response => { if (response.ack === 0) console.log('nothing to delete') }
python
from nandboxbots.util.DocumentStore import DocumentStore DocumentStore.get_instance().delete_document(api, "orders", "42", "123456789") # in the callback def on_document_response(self, response): if response.ack == 0: print("nothing to delete")

Response

json
{ "method": "deleteDocumentResponse", "collection": "orders", "document_id": "42", "app_id": "90090684293000559", "reference": "123456789", "ack": 1 }