CodesJava

Easy learning with example program codes

Delete Database in PouchDB

PouchDB Delete Database

To delete a database in PouchDB, the db.destroy() method is used.

Syntax:

db.destroy()

Example:

  • Open Node.js command prompt.
  • Create a file named “DeleteExample.js” within a folder named “Examples”.
  • Add the below code to the file.
    DeleteExample.js:

    var PouchDB = require('PouchDB');
    var db = new PouchDB('Example_Database');
    db.destroy(function (err, response) {
    if (err) {
    return console.log(err);
    } else {
    console.log ("Database Successfully Deleted.");
    }
    });
  • Open the command prompt.
  • Execute the .js file.
    node DeleteExample.js
    

    Console Output:

    Database Successfully Deleted.

 

Delete a Remote Database:

At the place of the database name, pass the path to the required database in CouchDB to delete a database that is located on CouchDB.
Example:

  • Open Node.js command prompt.
  • Create a file named “DeleteRemoteExample.js” within a folder named “Examples”.
  • Add the below code to the file.
    DeleteRemoteExample.js:

    var PouchDB = require('pouchdb');
    var db = new PouchDB('http://localhost:5984/students');
    db.destroy(function (err, response) {
    if (err) {
    return console.log(err);
    } else {
    console.log("Database Successfully Deleted.");
    }
    });
  • Open the command prompt.
  • Execute the .js file.
    node DeleteRemoteExample.js
    

     
    Console Output:

    Database Successfully Deleted.

Verification:

Check that the deleted database is not available any more on the CouchDB server.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status