PouchDB Create DocumentThe db.put() method is used to create a document in PouchDB database. The document that is created in PouchDB database is stored in a variable and pass as a parameter to this method. This method can also accepts a callback (optional) function as a parameter. Syntax: Create Document ExampleLet's first create a database named "Second_Database" in PouchDB because we have deleted the previous one. Visit: How to create database in PouchDB Use put() method to create a document. The created document should be in JSON format, a set of key-value pairs separated by comma (,) and enclosed within curly braces ({}). Save the above code in a file named "Create_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Insert a Document in Remote DatabaseYou can also insert a document in a remotely stored database (CouchDB). You just have to 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 ExampleWe have a database named "employees" on CouchDB. This database has no documents within it as you can see in below image: Let's see how to insert a document in the database named "employees" saved on CouchDB server. Save the above code in a file named "Create_Remote_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: VerificationYou can verify that the document is created by visiting the "employees" database on CouchDB Server. Next TopicPouchDB Read Document |