PouchDB Create BatchBatch is an array of documents in PouchDB. The db.bulkDocs() method is used to create an array of documents or batch. While creating documents, if you don't provide _id values then on your behalf PouchDB generates unique ids for all the documents in the bulk. You can store all the documents that you want to create in PouchDB in an array and pass it to this method as a parameter. This method also accepts a callback (optional) function as a parameter. Syntax: Create Batch ExampleLet's create multiple documents in PouchDB using the db.bulkDocs () method. The documents should be in JSON format, a set of key-value pairs separated by comma (,) and enclosed within curly braces ({}). The batch will be created in database named "Second_Database" stored on PouchDB server. Save the above code in a file named "Create_Batch.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Output: Create a Batch in Remote DatabaseYou can create a batch in a database which is stored remotely on CouchDB Server. For this, you have to pass the path of the database where you want to create the batch. ExampleWe have a database named "employees" on the CouchDB Server. There is no document in "employees" database. Let's create a batch in "employee" database. Save the above code in a file named "Create_Remote_Batch.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Output: VerificationYou can see the created documents on CouchDB server. Next TopicPouchDB Read Batch |