PouchDB Delete Batch
PouchDB Delete Batch
- bulkDocs() - This method is used to delete an array of documents in PouchDB. We know the _id and _rev values of the documents that we need to delete from the database.
- We have a database named "Second_Database" stored in PouchDB and contains 3 documents:
PouchDB Delete Batch
Here delete the documents using their respective _id and _rev values:
- Save the above code in a file named "Delete_Batch.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
Output:
PouchDB Delete Batch
- The batch is now deleted. You can also verify it.
Read Also
Verification
PouchDB Delete Batch
- You can see that there is no document in database.
Delete a Batch from Remote Database
Additionally we can delete an array of documents in a database that is stored remotely on a server (CouchDB). For this purpose, You just have to pass the path to the database where you want to delete the documents in CouchDB.
- We have a database named "employees" in the CouchDB Server.
PouchDB Delete Batch
- There are three documents in "employees" database
PouchDB Delete Batch
- You can fetch these documents by using node (Read_Remote_Batch.js) command.
PouchDB Delete Batch
- Now delete all the documents of database "employees".
Read Also
Save the file name as "Delete_Remote_Batch.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the javascript file using node.
Output:
PouchDB Delete Batch
Verification
- You can see that there is no document in "employees"database.
PouchDB Delete Batch