Javatpoint Logo
Javatpoint Logo

PouchDB Delete Batch

The bulkDocs() method is used to delete an array of documents in PouchDB. You just have to know the _id and _rev values of the documents that you want to delete from the database. You have to add another key-value pair _deleted: true.

We have a database named "Second_Database" stored in PouchDB and contains 3 documents:

PouchDB Delete batch 1

Let's 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 2

The batch is now deleted. You can also verify it.


Verification

PouchDB Delete batch 3

You can see that there is no document in database.


Delete a Batch from Remote Database

We can also delete an array of documents in a database that is stored remotely on a server (CouchDB). You just have to pass the path to the database in CouchDB, which contains the document that you want to delete.

Example

We have a database named "employees" in the CouchDB Server.

PouchDB Delete batch 4

There are three documents in "employees" database

PouchDB Delete batch 5

You can fetch these documents by using node (Read_Remote_Batch.js) command.

PouchDB Delete batch 6

Now delete all the documents of database "employees".

Save the above code in a file named "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 7

Verification

You can see that there is no document in "employees"database.

PouchDB Delete batch 8



Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA