PouchDB Update Document
PouchDB Update Document
- A document in PouchDB can be updated by using the (_rev). A _rev is created when we make a document in PouchDB. It is called revision marker.
- The _rev's value includes a unique random number. To update a document, you have to recover _rev value of the document which we need to update.
- Now, place the contents that are to be updated along with the retrieved _rev value in a new document, and finally embed this document in PouchDB using the put() method.
Update Document Example
- To retrieve the data form the document, first you need to get _rev number.
- Now use the _rev and update the value of "age" to 25. See the following code:
- Save the file named as "Update_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and Execute the JavaScript file:
Output:
PouchDB Update Document
Update a Document in Remote Database
You can also update the existing document in a remotely stored database(CouchDB). For this purpose, You just pass the path of the database where you want to update the documents in CouchDB.
Example
- We have a database named "employees" on the CouchDB Server.
PouchDB Update Document
- By clicking on "employees", you will find that it has a document.
PouchDB Update Document
- Let's update name and age of the document having id "001" that exists in database "employees" and stored on CouchDB Server.
Updating:
- Save the above code in a file named "Update_Remote_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
Read Also
Output:
- You can also see that document has been successfully changed on CouchDB server.