PouchDB Create Batch
PouchDB Create Batch
PouchDB Create Batch
- Batch - It is an array of documents in PouchDB.
- db.bulkDocs() - It is used to create an array of documents or batch.
- You'll be able store all the documents that you need to form in PouchDB in an array and pass it to this method as a parameter. This method additionally takes a callback function as a parameter.
Syntax
Create Batch Example
db.bulkDocs() method is used to create multiple documents in PouchDB. Documents must be in JSON Format, a set of key-value pairs separated by comma (,) and enclosed within curly brace({}).
- Save the file name as "Create_Batch.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
Output
PouchDB Create Batch
Create a Batch in Remote Database
We can create a batch in a database which is stored remotely on CouchDB Server. For this purpose, we have to pass the path of the database where we need to create the batch.
Example
- We have a database named "employees" on the CouchDB Server.
Let's create a batch in "employee" database.
- Save the file name as "Create_Batch_Remote.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
Output:
PouchDB Create Batch
Verification
- You can see the created documents on CouchDB server.
PouchDB Create Batch