You can erase a variety of records in PouchDB without a moment's delay utilizing the bulkDocs() technique. To do so you need to make a variety of reports that are to be erased where, each archive ought to contain _id and _rev. Notwithstanding these you need to add another key-esteem pair _deleted: valid.
Assume the data set named my_database that is put away locally in PouchDB contains 3 reports to be specific doc1, doc2, doc3 with the accompanying substance.
doc1 = {_id: '001', name: 'Ram', age: 23, Designation: 'Programmer'}
doc2 = {_id: '002', name: 'Robert', age: 24, Designation: 'Programmer'}
doc3 = {_id: '003', name: 'Rahim', age: 25, Designation: 'Programmer'}
Furthermore, state, we need to erase all the three reports. At that point, above all else you need to get their _rev values. In this way, bring the substance of these reports utilizing the accompanying code.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Retrieving all the documents in PouchDB
db.allDocs({include_docs: true},function(err, docs) {
if (err) {
return console.log(err);
} else {
console.log(docs.rows);
}
});
Save the above code as bulk_fetch.js. Executing the above program gives you the _id and _rev estimations of the archives in the data set as demonstrated underneath.
[
{
id: '001',
key: '001',
value: { rev: '1-1604b0c3ff69dc1e261265fd60808404' }
},
{
id: '002',
key: '002',
value: { rev: '1-b5e49db7e984841bf12a13e3ee548125' }
},
{
id: '003',
key: '003',
value: { rev: '1-a7b342786ecc707aa91f3b321a177b51' }
}
]
Presently, you can erase the records utilizing their particular _id and _rev values as demonstrated underneath.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Preparing the document
docs = [{_id : '001', _rev: '2-77f3a9974dd578d12f3f2a33aae64c8d', _deleted : true },
{_id : '002', _rev: '2-43966007568ce9567c96422195fcfa0d', _deleted : true },
{_id : '003', _rev: '2-6c5349652527f4f39583ff14f23cd677',_deleted : true }]
//Deleting Documents
db.bulkDocs(docs, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log(response+"Documents deleted Successfully");
}
});
Save the above code in a document with the name Delete_All_Document.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Delete_All_Document.js
This erases all the reports that exists in the data set named my_database which is put away locally, showing the accompanying message.
Documents Deleted Successfully
Presently, on the off chance that you execute the bulk_fetch.js program, you can notice a vacant support on the reassure demonstrating that the data set is unfilled, as demonstrated underneath.
[]
Deleting Batch from a Remote Database
You can refresh all the reports from the data set that is put away distantly on the worker (CouchDB).
To do as such, rather than a data set name, you need to pass the way to the data set in CouchDB, which contains the report that will be perused.
Example
Assume there is a data set named my_database in the CouchDB worker. At that point, in the event that you check the rundown of information bases in CouchDB utilizing the URL http://127.0.0.1:5984/_utils/index.html you will get the accompanying screen capture.
On the off chance that we select the information base named my_database, you can see that it contains 3 reports as demonstrated in the accompanying screen capture.
Following is an illustration of erasing all the records that exist in a data set named my_database which is put away in the CouchDB worker.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('http://localhost:5984/my_database');
//Preparing the document
docs = [{_id : '001', _rev: '4-6bc8d9c7a60fed2ed1667ec0740c1f39', _deleted : true },
{_id : '002', _rev: '2-1aa24ce77d96bb9d2a0675cdf1e113e0', _deleted : true },
{_id : '003', _rev: '2-fa113149ba618eda77f73072974a2bc1',_deleted : true }]
//Deleting Documents
db.bulkDocs(docs, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Documents deleted Successfully");
}
});
Save the above code in a record with name Remote_delete_AllDocuments.js. Open the order incite and execute the JavaScript record utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Remote_Delete_AllDocuments.js
This erases the substance of all given report that exists in the information base named my_database which is put away in CouchDB, and showcases the accompanying message.
Documents Deleted Successfully