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

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×