PouchDB Add Attachment
PouchDB Add Attachment
PouchDB Add Attachment
Syntax
Add Attachment Example
To create a document with an attachment in a newly created database "New_Database".
- Save the file name as "Add_Attachment.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the javascript file using node.
PouchDB Add Attachment
Verification
- Save the above code in a file named "read_doc_attach.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
PouchDB Add Attachment
Add attachment to an existing document
- We have a document in database named "Last_Database" with id "002". You can see the value of the document:
- Now add an attachment to this document using its _rev value.
Example:
Save the file name as "Add_Attachment2.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the javascript file using node.
Output:
PouchDB Add Attachment
Add Attachment to a Remote Database Example
- Additionally we can add an attachment to a remotely stored server (CouchDB). For this purpose, You just have to pass the path to the database where you need to add your attachment in CouchDB.
- We have a database name "employees" stored on the CouchDB server.
PouchDB Add Attachment
Add an attachment to the document 001 stored in a database named "employees" which is stored in the CouchDB server.
Save the above code in a file named "Add_Remote_Attachment.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node:
PouchDB Add Attachment
Verification
Go to CouchDB server and we can see that attachment is added with the document.