PouchDB in Hindi Deleting Attachment




Delete किये गए Attachment () का उपयोग करके PouchDB से एक Attachment को हटाया जा सकता है.

Syntax

removeAttachment() Method एक Syntax है. इस Method के लिए हमें document id, Attachment id, and _rev Value को देना होता है. यह Method एक Alternative Callback Function को भी स्वीकार करता है.

db.removeAttachment ( docId, attachmentId, rev, [callback] );

Example

हमारे पास Id 002 के साथ PouchDB में एक Document है, जिसमें Attachment वाले एक कर्मचारी का Id, Name, Age, पद शामिल है.

{ name: 'Altamas',  
  age: 22,  
  designation: 'Developer',  
  _attachments:  
   { 'attachment1.txt':  
      { content_type: 'text/plain',  
        revpos: 2,  
        digest: 'md5-k7iFrf4NoInN9jSQT9WfcQ==',  
        data: 'AA==' } },  
  _id: '002',  
  _rev: '2-388510d44393457cb06764dd89542ef3' }  

अब हम removeAttachment() Method का उपयोग करके Attachment को हटाते है.

//Requiring the package  
var PouchDB = require('PouchDB');  
//Creating the database object  
var db = new PouchDB('Last_Database');  
db.removeAttachment('002', 'attachment_1.txt', '2-388510d44393457cb06764dd89542ef3',  
function(err, res) {  
if (err) {  
  return console.log(err);  
} else {  
  console.log(res+"Attachment Deleted successfully")  
}  
});  

अब हम एक Folder PouchDB_Examples के Name से बनाते है और उसमे "Delete_Attachment.js" नामक File में Code को Save कर लेते है.

node Delete_Attachment.js 

Output

C:\Users\Altamas Ali\Desktop\PouchDB_Examples>node Delete_Attachment.js
[object Object] Attachment Deleted Successfully

C:\Users\Altamas Ali\Desktop\PouchDB_Examples>

Verification

आप इसको Verify कर सकते हो Read Command का उपयोग करके की Document से Attachment को Deleted कर दिया गया है.

C:\Users\Altamas Ali\Desktop\PouchDB_Examples>node Read_Document2.js
{ name: 'Altamas',  
  age: 22,  
  designation: 'Developer',
_id: '002',
_rev: '1-06272bacc14146d68d8ee0c36dfa0cb9'}

C:\Users\Altamas Ali\Desktop\PouchDB_Examples>