'How do I bulk delete documents in Cloudant-Node-SDK?
I am using the Cloudant-Node-SDK and I want to bulk delete some documents. How can I do that?
Solution 1:[1]
The postBulkDocs function allows to insert, update or delete multiple documents with one call.
To delete, call it with a _deleted flag in each document.
For example, if you have these three docs (you only need their _id and _rev to delete):
var docs = [{
_id: '0007241142412418284',
_rev: '2-4567766',
_deleted: true
},
{
_id: '000459458904590453',
_rev: '3-59695945',
_deleted: true
},
{
_id: '0004590650650678',
_rev: '2-796865867967',
_deleted: true
}]
..then as long as they each have a _deleted:true flag in the body, then they will be deleted when you call the postBulkDocs function:
await service.postBulkDocs({
db: 'mydb',
bulkDocs: {"docs":docs}
})
There are more examples in the API documentation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Mermelstein |
