You can peruse/recover the substance of an archive in PouchDB utilizing the db.get() strategy.
Syntax
Following is the grammar of utilizing the db.get() strategy for PouchDB. This technique acknowledges the archive id and a discretionary callback work.
db.get(document, callback)
Example
Following is an illustration of perusing the substance of a report in PouchDB utilizing the get() technique.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Reading the contents of a Document
db.get('001', function(err, doc) {
if (err) {
return console.log(err);
} else {
console.log(doc);
}
});
Save the above code in a document with name Read_Document.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Read_Document.js
This peruses the substance of the given report that exists in the data set named my_database which is put away locally. The accompanying message gets shown on the reassure.
{
name: 'Raju',
age: 23,
designation: 'Designer',
_id: '001',
_rev: '1-ba7f6914ac80098e6f63d2bfb0391637'
}
Reading a Document from a Remote Database
You can likewise peruse a record from the information base that is put away distantly on the worker (CouchDB).
To do as such, rather than an information base name, you need to pass the way to the data set in CouchDB, which contains the report that will be perused.
Example
Assume, there is a data set named my_database in the CouchDB worker. At that point, in the event that you confirm 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.
By tapping on the information base named my_database you can see the accompanying screen capture. Here, you can see that this data set contains a report with id 001.
Following is an illustration of perusing the substance of the record having id as "001" that exists in a data set named my_database, which is put away in the CouchDB worker.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('http://localhost:5984/my_database');
//Reading the contents of a document
db.get('001', function(err, doc) {
if (err) {
return console.log(err);
} else {
console.log(doc);
}
});
Save the above code in a record with the name Remote_Read_Document.js. Open the order incite and execute the JavaScript record utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Remote_Read_Document.js
This peruses the substance of the given record that exists in the data set named my_database which is put away in CouchDB. The accompanying message is shown on the comfort.
{
_id: '001',
_rev: '3-552920d1ca372986fad7b996ce365f5d',
name: 'Raju',
age: 23,
designation: 'Designer'
}