You can recover a connection from PouchDB utilizing the getAttachment() technique. This technique consistently returns mass or support objects.
Syntax
Following is the language structure of the getAttachment(). To this technique, we need to pass the report id and connection id. This technique likewise acknowledges a discretionary callback work.
db.getAttachment( docId, attachmentId, [callback] );
Example
Following is an illustration of recovering a connection of a record put away in PouchDB, utilizing getAttachment() strategy. Utilizing this code, we are attempting to recover a connection att_1.txt from the record 001.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Retrieving an attachment from a document
db.getAttachment('001', 'att_1.txt', function(err, blob_buffer) {
if (err) {
return console.log(err);
} else {
console.log(blob_buffer);
}
});
Save the above code in a record with the name Retrieve_Attachment.js. Open the order provoke and execute the JavaScript document utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Retrieve_Attachment.js
This recovers the connection of the record and shows on the reassure as demonstrated beneath.
<Buffer 00>
Retrieving Attachment from a Remote Document
You can likewise recover a connection of an archive existing in the information base that is put away distantly on the worker (CouchDB).
To do as such, rather than a data set name, you need to pass the way to the data set in CouchDB, which contains the report 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 check 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.
On the off chance that you select the information base named my_database, you can see its substance as demonstrated beneath.
Assume, there is a connection in this record as demonstrated underneath.
Following is an illustration of recovering a connection of the report 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');
//Retrieving an attachment from a document
db.getAttachment('001', 'att_1.txt', function(err, blob_buffer) {
if (err) {
return console.log(err);
} else {
console.log(blob_buffer);
}
});
Save the above code in a document with the name Remote_Retrieve_Attachment.js. Open the order incite and execute the JavaScript record utilizing hub as demonstrated beneath.
C:\PouchDB_Examples >node Remote_Retrieve_Attachment.js
This recovers the report connection and showcases it on the reassure as demonstrated beneath.
<Buffer 00>
