Database Info in PouchDB

Database Info

To get the information about a PouchDB database, the info () method is used in PouchDB.

Syntax:

db.info([callback])

Example:

  • Create a file named “InfoExample.js” within a folder name “Examples”.
  • Add the below code to the file. InfoExample.js

    var PouchDB = require('PouchDB');  
    var db = new PouchDB('Example_Database');  
    db.info(function(err, info) {  
       if (err) {  
          return console.log(err);  
       } else {  
          console.log(info);  
       }  
    });
  • Open the command prompt.
  • Execute the InfoExample.js file.
    node InfoExample.js

Remote Database Info:

At the place of the database name, pass the path to the required database in CouchDB, to get the information of a database that is located on CouchDB.

Example:

  • Create a file named “RemoteInfoExample.js” within a folder name “Examples”.
  • Add the below code to the file.RemoteInfoExample.js:
    var PouchDB = require('PouchDB');  
    var db = new PouchDB('http://localhost:5984/students');  
    db.info(function(err, info) {  
       if (err) {  
          return console.log(err);  
       } else {  
          console.log(info);  
       }  
    });
  • Open the command prompt.
  • Execute the RemoteInfoExample.js file.
    node RemoteInfoExample.js
    

    Output:

    { db_name: 'students',
     update_seq: '1-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUoxJTIkyf___z8rkQGPoiQFIJlkT1idA0h
     dPGF1CSB19QTV5bEASYYGIAVUOj8rkZGg2gUQtfuJMfcARO19YtQ-gKgFuTcLANTpby8',
     sizes: { file: 38080, external: 203, active: 360 },
     purge_seq: 0,
     other: { data_size: 203 },
     doc_del_count: 0,
     doc_count: 1,
     disk_size: 38080,
     disk_format_version: 6,
     data_size: 360,
     compact_running: false,
     instance_start_time: '0',
     host: 'http://localhost:5984/students/',
     auto_compaction: false,
     adapter: 'http' }
Please follow and like us:
Content Protection by DMCA.com