PouchDB Delete Document
PouchDB Delete Document
- db.remove() - It is used to delete a document from PouchDB database. You need to pass id and _rev value to delete an existing document.
- This method takes an optional parameter is callback function.
- Additionally, you can pass the completed document instead of id and _rev.
PouchDB Delete Document
Syntax:
Delete Document Example
To retrieve the value of document which you need to delete by using Read Document method.
Read Also
- This document is stored in a database named "Second_Database" in PouchDB.
PouchDB Delete Document
- To use remove() method with _rev value and id of the document.
- Save the document named "Delete_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and Execute the JavaScript file:
Output:
PouchDB Delete Document
Verification
- You'll be able confirm that your record is erased or not by recovering your document. In case it is erased it'll appear message:
PouchDB Delete Document
- You can see that document is deleted.
Delete a Document from Remote Database
You can also delete an existing document in a remotely stored database(CouchDB). For this purpose, You just pass the path of the database which contains the documents that you need to delete.
Example
- We have a database named "employees" on the CouchDB Server.
PouchDB Delete Document
- The employee database has a document having id "001".
Let's delete the above document.
- Save the above code in a file named "Delete_Remote_Document.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
Output:
PouchDB Delete Document
Verification
- Check CouchDB server. There is no document in "employee" database.
PouchDB Delete Document