In PouchDB, using the bulkDocs() method an array of documents can be deleted at once.
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.
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.
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.
On selecting the database named my_database, it can be observed that it contains 3 documents as shown in the screenshot below.
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.
PouchDB Related Interview Questions
|Java Script Interview Questions||Adv Java Interview Questions|
|Core Java Interview Questions||CorelDRAW Interview Questions|
|Angular JS Interview Questions||MYSQL DBA Interview Questions|
|NoSQL Interview Questions||CouchDB Interview Questions|
|MongoDB Interview Questions||Advanced C++ Interview Questions|
|Basic C Interview Questions||Stored Procedures Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.