PouchDB Update Batch
PouchDB Update Batch
- bulkDocs() - It is used to update an array of documents in PouchDB .
- To update a batch, we have to create an array of documents which contains _id, _rev and the values that we need to update.
- Let's update the documents using their individual_id and _rev values:
- Change the name and age of all three documents:
- Save the file name as "Update_Batch2.js " within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file.
Output
PouchDB Update Batch
Verification
- We can verify that the batch is updated by using node (Read_Batch) command:
PouchDB Update Batch
Update Batch in Remote Database
Additionally we can update an array of documents in a database that is stored remotely on a server (CouchDB). For this purpose, You just have to pass the path to the database where you want to update the documents in CouchDB.
- We have a database named "employees" in the CouchDB Server.
PouchDB Update Batch
- There are three documents in "employees" database
PouchDB Update Batch
- You can fetch these documents by using node (Read_Remote_Batch.js) command.
- Now update all the documents name and age of "employees" database stored on CouchDB Server.
- Save the file name as "Update_Remote_Batch.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the javascript file using node.
- It will update the documents in "employees" database.
Verification
- You can verify that the batch is updated by using node (Read_Remote_Batch) command:
PouchDB Update Batch