PouchDB Delete Database



PouchDB Delete Database

  • db.destroy() - Delete a database in PouchDB. This method takes a callback function as a parameter.

Syntax

db.destroy()  

Delete Database Example

To delete a database named "First_Database" in PouchDB, you can use the destroy() method.

//Requiring the package  
var PouchDB = require('PouchDB');  
//Creating the database object  
var db = new PouchDB('First_Database');  
//deleting database  
db.destroy(function (err, response) {  
   if (err) {  
      return console.log(err);  
   } else {  
      console.log ("Database Deleted");  
   }  
});  
  • Save the file "Delete_Database.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file:
node Delete_Database.js  
 PouchDB Delete Database

PouchDB Delete Database

Delete a Remote Database

You can delete a database that is stored remotely on the CouchDB server. You just have to pass the path of the CouchDB database which you need to delete instead of database name.

  • The following example will delete a database that is saved in the CouchDB server. This following code will delete the database named "employees".
 PouchDB Delete Database

PouchDB Delete Database

//Requiring the package  
var PouchDB = require('pouchdb');  
//Creating the database object  
var db = new PouchDB('http://localhost:5984/employees');  
//deleting database  
db.destroy(function (err, response) {  
   if (err) {  
      return console.log(err);  
   } else {  
      console.log("Database Deleted");  
   }  
});  
  • Save the above code in a file named "Delete_Remote_Database.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file:
node Delete_Remote_Database.js   
 PouchDB Delete Database

PouchDB Delete Database

Output

Now the "employees" database is deleted. You can verify it on CouchDB server. You can see that "employees" database is not available in the database's list.

 PouchDB Delete Database

PouchDB Delete Database



Related Searches to PouchDB Delete Database