Home » Pouchdb Delete Document

Pouchdb Delete Document

by Online Tutorials Library

PouchDB Delete Document

The db.remove() method is used to delete a document from PouchDB database. You have to pass id and _rev value to delete an existing document. This method accepts an optional callback function. You can also pass the complete document instead of id and _rev.

Syntax:


Delete Document Example

First retrieve the value of a document which you want to delete by using Read Document method.

This document is stored in a database named “Second_Database” in PouchDB.

PouchDB Delete document 1

Now, use remove() method with _rev value and id of the document.

Save the above code in a file named “Delete_Document.js” within a folder name “PouchDB_Examples”. Open the command prompt and execute the JavaScript file using node:

Output:

PouchDB Delete document 2


Verification

You can verify that your document is deleted or not by retrieving your document. If it is deleted it will show message:

PouchDB Delete document 3

You can see that document is deleted.


Delete a Document from Remote Database

You can delete an existing document in a database which is stored remotely on CouchDB Server. For this, you have to pass the path of the database which contains the document that you want to delete.

Example

We have a database named “employees” on the CouchDB Server.

PouchDB Delete document 4

The employee database has a document having id “001”.

PouchDB Delete document 5

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 6


Verification

Check CouchDB server. There is no document in “employee” database.

PouchDB Delete document 7

You may also like