You can erase a connection from PouchDB utilizing the removeAttachment() strategy.
Syntax
Following is the language structure of the removeAttachment() strategy. To this strategy, we need to pass the record id, connection id, and _rev esteem. This strategy additionally acknowledges a discretionary callback work.
db.removeAttachment ( docId, attachmentId, rev, [callback] );
Example
Assume there is a report in PouchDB with id 001, which contains id, name, age, assignment of a worker alongside a connection as demonstrated underneath.
{
name: 'Raju',
age: 23,
designation: 'Designer',
_attachments: {
'att_1.txt': {
content_type: 'text/plain',
digest: 'md5-k7iFrf4NoInN9jSQT9WfcQ==',
data: 'AA=='
}
},
_id: '001',
_rev: '2-cdec6c9f45ddbee7d456945654742d43'
}
Following is an illustration of erasing the connection of this report 001 put away in PouchDB, utilizing removeAttachment() strategy.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my');
db.removeAttachment('001', 'att_1.txt', '2-cdec6c9f45ddbee7d456945654742d43',
function(err, res) {
if (err) {
return console.log(err);
} else {
console.log(res+"Attachment Deleted successfully")
}
});
Save the above code in a record with the name Remove_Attachment.js. Open the order incite and execute the JavaScript record utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Remove_Attachment.js
This eliminates the connection of the report and shows a message on the support as demonstrated underneath.
Attachment deleted successfully
After erasure, you can check the substance of the report by executing the accompanying code.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_d');
//Reading the Document
db.get('001',{attachments: true}, function(err, doc) {
if (err) {
return console.log(err);
} else {
console.log(doc);
}
});
Save this code as read.js and execute it. On executing, you will get the substance of the archive subsequent to erasing the connection, as demonstrated beneath.
{
name: 'Raju',
age: 23,
designation: 'Designer',
_id: '001',
_rev: '3-da775487a6ed0495f2e49c543384f8e8'
}
Removing Attachment from a Remote Document
You can erase a connection of a current archive in the data set that is put away distantly on the worker (CouchDB).
To do as such, rather than an information base name, you need to pass the way to the data set in CouchDB, which contains the record that will be perused.
Example
Assume there is an information base named my_database in the CouchDB worker. At that point, on the off chance that you confirm the rundown of information bases in CouchDB utilizing the URL http://127.0.0.1:5984/_utils/index.html you will get the accompanying screen capture.
What's more, on the off chance that you select the information base named my_database, you can see its substance as demonstrated underneath.
Assume there is a connection in this record as demonstrated beneath.
Following is an illustration of erasing the previously mentioned connection of the record 001 that exists in an information base named my_database which is put away in the CouchDB worker.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('http://localhost:5984/my_database');
db.removeAttachment('001', 'att_1.txt', '2-049f1c4ffa54576ec0947b65e34de423',
function(err, res) {
if (err) {
return console.log(err);
} else {
console.log(res+"Attachment Deleted successfully")
}
});
Save the above code in a record with the name Remote_Delete_Attachment.js. Open the order provoke and execute the JavaScript record utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Remote_Delete_Attachment.js
This eliminates the current connection and presentations the accompanying message.
Attachment Deleted successfully
In the event that you visit the record once more, you can see that the connection was erased as demonstrated in the accompanying screen capture.