PouchDB Deleting Attachment - PouchDB

What is PouchDB - Deleting Attachment?

An attachment can be deleted from PouchDB using the removeAttachment() method.

Syntax

Following is the syntax of the removeAttachment() method. To this method, we have to pass the document id, attachment id, and _rev value. This method also accepts an optional callback function.

Example

Suppose there is a document in PouchDB with id 001, which contains id, name, age, designation of an employee along with an attachment as shown below.

An example of deleting the attachment of this document 001 stored in PouchDB, using removeAttachment() method is given below.

Save the above code in a file named Remove_Attachment.js. Open the command prompt and execute the JavaScript file using node as shown below.

With this the attachment of the document is deleted and a message is displayed on the console as shown below.

After deletion, the contents of the document can be verified by executing the following code.

Save this code as read.js and execute it. On executing, the contents of the document after deleting the attachment are given, as shown below.

Removing Attachment from a Remote Document

An attachment of an existing document can be deleted in the database that is stored remotely on the server (CouchDB).

To do so, instead of a database name, you need to pass the path to the database in CouchDB, which contains the document that is to be read.

Example

Suppose there is a database named my_database in the CouchDB server. Then, if the list of databases in CouchDB is verified using the URL http://127.0.0.1:5984/_utils/index.html you will get the following screenshot.

On selecting the database named my_database, its contents can be viewed as shown below.

PouchDB - Deleting Attachment

Suppose there is an attachment in this document as shown below.

PouchDB - Deleting Attachment

An example of deleting the above mentioned attachment of the document 001 that exists in a database named my_database which is stored in the CouchDB server is given below.

Save the above code in a file with the name Remote_Delete_Attachment.js. Open the command prompt and execute the JavaScript file using node as shown below.

With this the existing attachment is removed and the following message is displayed.

On visiting the document again, the deleted attachment can be noticed as shown in the following screenshot.

PouchDB - Deleting Attachment

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PouchDB Topics