You can peruse/recover different/mass records from a data set in PouchDB utilizing the allDocs() technique.
Syntax
Following is the language structure of utilizing the db.allDocs() strategy for PouchDB. This strategy acknowledges a discretionary callback work.
db.allDocs()
Example
Following is an illustration of recovering all the reports in a data set named my_database that is put away locally, utilizing db.allDocs() strategy. This technique recovers the variety of archives as articles, to get the substance of each record you need to call as docs.rows.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Retrieving all the documents in PouchDB
db.allDocs(function(err, docs) {
if (err) {
return console.log(err);
} else {
console.log (docs.rows);
}
});
Save the above code in a record with the name Read_All_Document.js. Open the order provoke and execute the JavaScript document utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Read_All_Document.js
This peruses all the archives that exists in the data set named my_database which is put away locally. The accompanying message is shown on the support.
[
{
id: '001',
key: '001',
value: { rev: '1-9dc57f5faa7ea90eeec22eba8bfd05f5' }
},
{
id: '002',
key: '002',
value: { rev: '1-9bf80afcedb9f8b5b35567292affb254' }
},
{
id: '003',
key: '003',
value: { rev: '1-1204f108e41bf8baf867856d5da16c57' }
}
]
By and large, as demonstrated in the above outcome, utilizing allDocs() strategy you can see just the _id, key and _rev fields of each archive. Notwithstanding, to remember the entire archive for the outcome, you need to make the discretionary boundary include_docs valid as demonstrated underneath.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Retrieving all the documents in PouchDB
db.allDocs({include_docs: true}, function(err, docs) {
if (err) {
return console.log(err);
} else {
console.log (docs.rows);
}
});
Executing the above code gives you a rundown of complete archives in the predefined reports as demonstrated in the accompanying code.
[
{
id: '001',
key: '001',
value: { rev: '1-9dc57f5faa7ea90eeec22eba8bfd05f5' },
doc: {
name: 'Ram',
age: 23,
Designation: 'Programmer',
_id: '001',
_rev: '1-9dc57f5faa7ea90eeec22eba8bfd05f5'
}
},
{
id: '002',
key: '002',
value: { rev: '1-9bf80afcedb9f8b5b35567292affb254' },
doc: {
name: 'Robert',
age: 24,
Designation: 'Programmer',
_id: '002',
_rev: '1-9bf80afcedb9f8b5b35567292affb254'
}
},
{
id: '003',
key: '003',
value: { rev: '1-1204f108e41bf8baf867856d5da16c57' },
doc: {
name: 'Rahim',
age: 25,
Designation: 'Programmer',
_id: '003',
_rev: '1-1204f108e41bf8baf867856d5da16c57'
}
}
]
Reading a Batch from a Remote Database
You can likewise bring all the records from the data set that is put away distantly on the worker (CouchDB).
To do as such rather than a data set name, you need to pass the way to the data set in CouchDB, which contains the record that will be perused.
Example
Assume there is a data set named my_database in the CouchDB worker. At that point, on the off chance that you check the rundown of information bases in CouchDB utilizing the URL http://127.0.0.1:5984/_utils/index.html you will get the accompanying screen capture.
Following is an illustration of perusing all the records that exist in an information base 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');
//Retrieving all the documents in PouchDB
db.allDocs({include_docs: true}, function(err, docs) {
if (err) {
return console.log(err);
} else {
console.log(docs.rows);
}
});
Save the above code in a record with the name Remote_Read_AllDocument.js. Open the order incite and execute the JavaScript document utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Remote_Read_AllDocument.js
This peruses the substance of the given archive that exists in the information base named my_database which is put away in CouchDB, and showcases on the support as demonstrated beneath.
[
{
id: '001',
key: '001',
value: { rev: '3-552920d1ca372986fad7b996ce365f5d' },
doc: {
_id: '001',
_rev: '3-552920d1ca372986fad7b996ce365f5d',
name: 'Raju',
age: 23,
designation: 'Designer'
}
},
{
id: '002',
key: '002',
value: { rev: '1-9af15cb11054ebe03a7816bf6c5e4128' },
doc: {
_id: '002',
_rev: '1-9af15cb11054ebe03a7816bf6c5e4128',
name: 'Robert',
age: 24,
Designation: 'Programmer'
}
},
{
id: '003',
key: '003',
value: { rev: '1-3033b5a78e915c52fd37325d42eb3935' },
doc: {
_id: '003',
_rev: '1-3033b5a78e915c52fd37325d42eb3935',
name: 'Rahim',
age: 25,
Designation: 'Programmer'
}
}
]