PouchDB Read Batch
PouchDB Read Batch
allDocs() method in pouchdb is used to retrieve or read bulk or multiple documents from a database. This method takes a callback function as optional parameter.
Syntax
Example
- Save the file name as "read_batch.js " within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
Output
PouchDB Read Batch
Generally, allDocs() method we can see only the _id, key and _rev fields of each document. If we need to see the whole document in the result, you have to make the optional parameter include_docs true.
- Save the file name as "Read_Batch2.js " within a folder name "PouchDB_Examples". Open the command prompt and execute the javascript file.
Output
PouchDB Read Batch
Read a Batch from Remote Database
We can read a batch from a database which is stored remotely on CouchDB Server. For this purpose, we have to pass the path of the database where you need to read the batch.
- We have a database named "employees" on the CouchDB Server.
PouchDB Read Batch
PouchDB Read Batch
- Let's read all the documents from the "employees" database stored on CouchDB Server.
- Open the command prompt and execute the JavaScript file using node:
Output:
PouchDB Read Batch