You can make a cluster (bunch) of reports in PouchDB utilizing the db.bulkDocs() technique. While making archives, utilizing this strategy on the off chance that we don't give _id values, for our sake PouchDB produces one of a kind ids for all the reports in the mass.
Syntax
Following is the grammar of utilizing the db.bulkDocs() strategy for PouchDB. You can store all the records that are to be made in PouchDB in a cluster and pass it to this strategy as a boundary. Notwithstanding it, this technique likewise acknowledges a callback (discretionary) work as a boundary.
db.bulkDocs(docs, [options], [callback])
Example
Following is an illustration of making various reports in PouchDB utilizing the db.bulkDocs () strategy. The archives we make ought to be of JSON design, a bunch of key-esteem sets isolated by comma (,) and encased inside wavy supports ({}).
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Preparing the documents array
doc1 = {_id: '001', name: 'Ram', age: 23, Designation: 'Programmer'}
doc2 = {_id: '002', name: 'Robert', age: 24, Designation: 'Programmer'}
doc3 = {_id: '003', name: 'Rahim', age: 25, Designation: 'Programmer'}
docs = [doc1, doc2, doc3]
//Inserting Documents
db.bulkDocs(docs, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Documents created Successfully");
}
});
Save the above code in a document with name Create_Batch.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Create_Batch.js
This makes the given report in PouchDB data set named my_database which is put away locally. The accompanying message gets shown.
Documents created Successfully
Inserting a Batch in a Remote Database
You can embed a variety of archives in 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 where we need to make reports in CouchDB.
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 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 embeddings a variety of records in the data set named my_database which is saved in the CouchDB worker.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('http://localhost:5984/my_database');
//Preparing the documents array
doc1 = {_id: '001', name: 'Ram', age: 23, Designation: 'Programmer'}
doc2 = {_id: '002', name: 'Robert', age: 24, Designation: 'Programmer'}
doc3 = {_id: '003', name: 'Rahim', age: 25, Designation: 'Programmer'}
docs = [doc1, doc2, doc3]
//Inserting Documents
db.bulkDocs(docs, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Documents created Successfully");
}
});
Save the above code in a record with the name Remote_Create_Batch.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Remote_Create_Batch.js
This makes the given reports in PouchDB data set named my_database which is put away in CouchDB. The accompanying message is shown.
Document created Successfully
Verification
Subsequent to executing the above program on the off chance that you visit the my_database once more, you can notice the records made as demonstrated in the accompanying screen capture.
