PouchDB Delete Attachment
PouchDB Delete Attachment
- removeAttachment() - This method is used to delete an attachment from PouchDB. To delete an attachment, We have to pass the document_id, attachment_id and _rev value.
- This method takes an callback function as a optional parameter.
PouchDB Delete Attachment
Syntax:
Example
We have a document in PouchDB with id 002, which contains id, name, age, designation of an employee with attachment.
- Let's remove the attachment by using removeAttachment() method.
Save the file name as "Del_Attachment.js " within a folder name "PouchDB_Examples". Open the command prompt and execute the javascript file using node.
Output
PouchDB Delete Attachment
- Attachment is deleted successfully.
Verification
Using read command to verify that the attachment is deleted from the document.
PouchDB Delete Attachment
Delete Attachment from a Remote Database
Additionally we can delete an attachment in a database that is stored remotely on a server (CouchDB). For this purpose, You just have to pass the path to the database where you want to delete the attachment in CouchDB.
Example
- We have a database name "employees" stored on the CouchDB server
PouchDB Delete Attachment
- The database "employees" has a document having id "001".
PouchDB Delete Attachment
- Let's delete the attachment.
Save the file name as "Delete_Remote_Attachment.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the javascript file using node.
Output:
PouchDB Delete Attachment