You can erase a data set in PouchDB utilizing the db.destroy() strategy.
Syntax
Following is the sentence structure of utilizing the db.destroy() strategy. This strategy acknowledges a callback work as a boundary.
db.destroy()
Example
Following is an illustration of erasing a data set in PouchDB utilizing the crush() strategy. Here, we are erasing the data set named my_database, made in the past sections.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//deleting database
db.destroy(function (err, response) {
if (err) {
return console.log(err);
} else {
console.log ("Database Deleted”);
}
});
Save the above code in a document with the name Delete_Database.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Delete_Database.js
This will erase the information base named my_database which is put away locally showing the accompanying message.
Database Deleted
Erasing a Remote Database
Similarly, you can erase a 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 that is needed to be erased, in CouchDB.
Example
Assume there is a data set named my_database in the CouchDB worker. At that point, on the off chance that you check the rundown of data sets in CouchDB utilizing the URL http://127.0.0.1:5984/_utils/index.html you will get the accompanying screen capture.
Following is an illustration of erasing a data set named my_database that is saved 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 database
db.destroy(function (err, response) {
if (err) {
return console.log(err);
} else {
console.log("Database Deleted");
}
});
Save the above code in a document with the name Remote_Database_Delete.js. Open the order provoke and execute the JavaScript document utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >Remote_Database_Delete.js
This erases the predetermined data set from PouchDB showing the accompanying message.
Database Deleted
Verification
Subsequent to executing the above program, on the off chance that you visit the URL once more, you will get the accompanying screen capture. Here you can notice just two information bases since my_database was erased.
