You can refresh a variety of reports in PouchDB immediately utilizing the bulkDocs() strategy. To do so you need to make a variety of archives where, each record contains _id, _rev and the qualities that are to be refreshed.
Assume the information base named my_database that is put away locally in PouchDB contains 3 archives to be specific doc1, doc2, doc3 with the accompanying substance.
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'}
Assume we need to expand the age esteems in all the 3 records by 2 years. For this to occur, first you need to get the _rev values. In this way, get the substance of these archives utilizing the accompanying code.
//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);
}
});
Save the above code as bulk_fetch.js. On executing, the above program gives you the _id and _rev estimations of the records in the information base as demonstrated underneath.
[
{
id: '001',
key: '001',
value: { rev: '1-1604b0c3ff69dc1e261265fd60808404' }
},
{
id: '002',
key: '002',
value: { rev: '1-b5e49db7e984841bf12a13e3ee548125' }
},
{
id: '003',
key: '003',
value: { rev: '1-a7b342786ecc707aa91f3b321a177b51' }
}
]
Presently, you can refresh the reports utilizing their separate _id and _rev values as demonstrated underneath.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_databas');
//Preparing the document
docs = [{_id : '001', _rev: '1-1604b0c3ff69dc1e261265fd60808404', age : 25, },
{_id : '002', _rev: '1-b5e49db7e984841bf12a13e3ee548125', age : 26, },
{_id : '003', _rev: '1-a7b342786ecc707aa91f3b321a177b51', age : 27 }]
//Updating the documents in bulk
db.bulkDocs(docs, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log("Documents Updated Successfully");
}
});
Save the above code in a record with the name Update_All_Document.js. Open the order incite and execute the JavaScript document utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Update_All_Document.js
This updates all the archives that exists in the data set named my_database which is put away locally, showing the accompanying message.
Documents Updated Successfully
Presently, on the off chance that you execute the bulk_fetch.js program by adding {include_docs: true} as a boundary to allDocs() work, before the callback, at that point, you will can see the estimations of the records refreshed, as demonstrated underneath.
[
{
id: '001',
key: '001',
value: { rev: '2-77f3a9974dd578d12f3f2a33aae64c8d' },
doc: {
age: 25,
_id: '001',
_rev: '2-77f3a9974dd578d12f3f2a33aae64c8d'
}
},
{
id: '002',
key: '002',
value: { rev: '2-43966007568ce9567c96422195fcfa0d' },
doc: {
age: 26,
_id: '002',
_rev: '2-43966007568ce9567c96422195fcfa0d'
}
},
{
id: '003',
key: '003',
value: { rev: '2-6c5349652527f4f39583ff14f23cd677' },
doc: {
age: 27,
_id: '003',
_rev: '2-6c5349652527f4f39583ff14f23cd677'
}
}
]
Updating Batch from a Remote Database
You can refresh all the archives from the information base 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 information base 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.
Also, accept in the event that we select the data set named my_database, you can see that it contains 3 records as demonstrated in the accompanying screen capture.
Presently, get the substance of these reports utilizing the accompanying code.
//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 as remote_bulk_fetch.js. On executing, the above program gives you the substance of the multitude of reports in the information base 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'
}
}
]
Following is an illustration of refreshing all the reports that exists 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');
//Preparing the document
docs = [{_id : '001', _rev: '3-552920d1ca372986fad7b996ce365f5d', age : 24, },
{_id : '002', _rev: '1-9af15cb11054ebe03a7816bf6c5e4128', age : 26, },
{_id : '003', _rev: '1-3033b5a78e915c52fd37325d42eb3935', age : 27}]
//Inserting Document
db.bulkDocs(docs, function(err, response) {
if (err) {
return console.log(err);
} else {
console.log(+"Documents Updated Successfully");
}
});
Save the above code in a record with the name Remote_Update_Document.js. Open the order incite and execute the JavaScript document utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Remote_Update_Document.js
This updates the substance of all given report that exists in the information base named my_database which is put away in CouchDB, and showcases the accompanying message.
Documents Updated Successfully
Presently, on the off chance that you execute the remote_bulk_fetch.js program you will can see the estimations of the records refreshed, as demonstrated beneath.
[
{
id: '001',
key: '001',
value: { rev: '4-6bc8d9c7a60fed2ed1667ec0740c1f39' },
doc: {
_id: '001',
_rev: '4-6bc8d9c7a60fed2ed1667ec0740c1f39',
age: 25
}
},
{
id: '002',
key: '002',
value: { rev: '2-1aa24ce77d96bb9d2a0675cdf1e113e0' },
doc: {
_id: '002',
_rev: '2-1aa24ce77d96bb9d2a0675cdf1e113e0',
age: 26
}
},
{
id: '003',
key: '003',
value: { rev: '2-fa113149ba618eda77f73072974a2bc1' },
doc: {
_id: '003',
_rev: '2-fa113149ba618eda77f73072974a2bc1',
age: 27
}
}
]