PouchDB Delete Batch - PouchDB

What is PouchDB - Delete Batch?

In PouchDB, using the bulkDocs() method an array of documents can be deleted at once.

For this, an array of documents that are to be deleted are to be created, where each document contains _id and _rev. An another key-value pair _deleted: true should also be added.

Let us suppose that the database named my_database that is stored locally in PouchDB consists of 3 documents namely doc1, doc2, doc3 with the contents given below.

.

Let us say, all the three documents are to be deleted. For this their _rev values are required. Therefore, the contents of these documents are to be fetched using the code given below

.

The above code is to be saved as bulk_fetch.js. On executing the above program, the _id and _rev values of the documents in the database are given as shown below.

Now, by using their respective _id and _rev values the documents can be deleted as shown below.

Create a file named Delete_All_Document.js and save the above code in it. Open the command prompt and by using node execute the Java Script file as shown below.

.

All the documents existing in the database named my_database which is stored locally are deleted and the meassage given below is displayed.

On executing the bulk_fetch.js program, empty brace on the console can be seen, which indicates that the database is empty, as shown below.

Deleting Batch from a Remote Database

All the documents from the database that are stored remotely on the CouchDB server can be deleted.
For this, the path to the database in CouchDB, which contains the document that is to be read, is passed instead of the name of the database.

Example

Let us consider the database named my_database in the CouchDB server. On verification of the list of databases in CouchDB using the URL http://127.0.0.1:5984/_utils/index.html, the screenshot given below is displayed.

PouchDB  Delete Batch

On selecting the database named my_database, it can be observed that it contains 3 documents as shown in the screenshot below.

PouchDB  Delete Batch

An example of deleting all the documents existing in a database named my_database which is stored in the CouchDB server is given below.

After creating a file named Remote_Create_Batch.js, save the above code in it. Open the command prompt and by using node execute the Java Script file as shown below.

The contents of all given documents existing in the database named my_database which is stored in CouchDB are deleted and the message given below is displayed.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PouchDB Topics