PouchDB Create Document
PouchDB Create Document
db.put() method - To create a new document in PouchDB database.
PouchDB Create Document
Syntax:
Document created in PouchDB database is stored in a variable and pass as a parameter to this method. This method can also takes a callback function as a parameter.
Create Document Example
- put() - To create a document.
- The created document must be in JSON format, a set of key-value pairs separated by comma (,) and enclosed within curly braces ({}).
- Save the file named as "Create_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file:
PouchDB Create Document
Insert a Document in Remote Database
- You can also insert a document in a remotely stored database (CouchDB). You just pass the path of the database where you want to create documents in CouchDB, instead of the database name.
Insert a Document in Remote Database Example
- We have a database named "employees" on CouchDB.
PouchDB Create Document
- Let's see how to insert a document within the database named "employees" saved on CouchDB server.
- Save the file named as "Create_Remote_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
Verification
Now You can verify that the document is created by visiting the "employees" database on CouchDB Server.
PouchDB Create Document
PouchDB Create Document