Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

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




Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA