You can erase a report from an information base that exists in PouchDB utilizing the db.remove() strategy.
Syntax
Following is the sentence structure of utilizing the db.remove() technique for PouchDB. To this technique, we need to pass id and _rev to erase a current archive as demonstrated in the accompanying code. This strategy acknowledges a discretionary callback work. We can likewise pass the total record rather than id and _rev.
db. get ( docId, docRev, [callback] )
or
db. get ( docId, docRev, [callback] )
Example
Expect we have an archive in PouchDB with id 001 which have the subtleties of an individual. To erase this report alongside its id we ought to likewise have its _rev number. Hence, recover the substance of the record as demonstrated in the accompanying code.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Reading the contents of a Document
db.get('001', function(err, doc) {
if (err) {
return console.log(err);
} else {
console.log(doc);
}
});
Executing the above code gives the accompanying yield.
{
_id: '001',
_rev: '3-552920d1ca372986fad7b996ce365f5d',
name: 'Raju',
age: 23,
designation: 'Designer'
}
Presently, utilizing the _rev and id of the archive you can erase this by utilizing the eliminate() technique as demonstrated in the accompanying code.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Deleting an existing document
db.remove('001', '3-552920d1ca372986fad7b996ce365f5d', function(err) {
if (err) {
return console.log(err);
} else {
console.log("Document deleted successfully");
}
});
Save the above code in a document with the name Delete_Document.js. Open the order incite and execute the JavaScript record utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Delete_Document.js
This erases the substance of the given archive that exists in the information base named my_database which is put away locally. The accompanying message is shown.
Document deleted successfully
Deleting a Document from a Remote Database
You can likewise erase a current archive from the information base 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 information base in CouchDB, which contains the archive that will be perused.
Example
Assume there is an information base named my_database in the CouchDB worker. At that point, on the off chance 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.
By tapping on the information base named my_database you can see the accompanying screen capture. Here, you can see that the information base contains a report with id 001.
Following is an illustration of erasing the substance of the report having id "001" that exists in an information base 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');
//Deleting an existing document
db.remove('001', '3-552920d1ca372986fad7b996ce365f5d', function(err) {
if (err) {
return console.log(err);
} else {
console.log("Document deleted successfully");
}
});
Save the above code in a record with name Remote_Delete_Document.js. Open the order incite and execute the JavaScript document utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Remote_Delete_Document.js
This erases the given archive that exists in the information base named my_database which is put away in CouchDB. The accompanying message is shown.
Document deleted successfully
