PouchDB Replication

To make a copy of a database, the feature of Replication of PouchDB serves the best. It works both for a locally stored PouchDB instance or a remotely stored CouchDB instance. Syntax: PouchDB.replicate(source, target, [options]) Replicating PouchDB (Local) to CouchDB: The documents doc1, doc2, and doc3 are present in the ‘Example_Database’ database in PouchDB. The … Read more

Delete Attachment in PouchDB

PouchDB Delete Attachment To delete an attachment from PouchDB, the removeAttachment() method is used. Syntax: db.removeAttachment ( doc_Id, attachment_Id, rev, [callback] ); Example: Create a file named “DeleteAttach.js” within a folder named “Examples”. Add the below code to the file. DeleteAttach.js: var PouchDB = require(’PouchDB’); var db = new PouchDB(’Example_Database’); db.removeAttachment(’101′, ‘attach_1.txt’, ‘1-f56789f432154adb782da98358921a14’, function(err, res) … Read more

Retrieve Attachment in PouchDB

PouchDB Retrieve Attachment To retrieve an attachment from PouchDB the getAttachment() method is used. It returns blob or the buffer objects. Syntax: db.getAttachment( docId, attachmentId, [callback] ); Example: Create a file named “RetrieveAttach.js” within a folder named “Examples”. Add the below code to the file. RetrieveAttach.js: var PouchDB = require(’PouchDB’); var db = new PouchDB(’Example_Database’); … Read more

Add Attachment in PouchDB

PouchDB Add Attachment To add a binary object to a PouchDB document, the putAttachment() method is used. Blob or buffer object also plays a vital role in this process. While working with browser Blob is preferred and while working with Node.js, a buffer object is preferred. Syntax: db.putAttachment( doc_Id, attachment_Id, attachment, type, callback );db.putAttachment( doc_Id, … Read more

Delete Batch in PouchDB

PouchDB Delete Batch To delete a PouchDB batch, the bulkDocs() method is used. Example: Retrieve the values of a bulk document. Output: [ {  id: ‘101’, key: ‘101’, value: { rev: ‘1-f56789f432154adb782da98358921a14’ }, doc: { name: ‘Tom’, salary: 25000, experience: 3, _id: ‘101’, _rev: ‘1-f56789f432154adb782da98358921a14’ } }, { id: ‘102’, key: ‘102’, value: { rev: … Read more

Update Batch in PouchDB

PouchDB Update Batch To update a batch in PouchDB, the bulkDocs() method is used. Example: Retrieve the values of a bulk document. Output: [ {  id: ‘101’, key: ‘101’, value: { rev: ‘1-f56789f432154adb782da98358921a14’ }, doc: { name: ‘Tom’, salary: 25000, experience: 3, _id: ‘101’, _rev: ‘1-f56789f432154adb782da98358921a14’ } }, { id: ‘102’, key: ‘102’, value: { … Read more

Read Batch in PouchDB

PouchDB Read Batch To retrieve a PouchDB batch, the allDocs() method is used. Syntax: db.allDocs() Example: Create a file named “ReadBatch.js” within a folder named “Examples”. Add the below code to the file. ReadBatch.js: var PouchDB = require(’PouchDB’); var db = new PouchDB(’Example_Database’); db.allDocs(function(err, docs) { if (err) { return console.log(err); } else { console.log … Read more

Create Batch in PouchDB

PouchDB Create Batch An array of documents is termed as Batch in PouchDB. To create a PouchDB batch The db.bulkDocs() method is used. If there are no unique _id values for each document then, PouchDB generates unique ids in bulk for all the documents. Syntax: db.bulkDocs(docs, [options], [callback]) Example: Create a file named “NewBatch.js” within … Read more

Delete Document in PouchDB

Delete Document To delete a PouchDB document the db.remove() method is used. Syntax: db.remove( doc_Id, doc_Rev, [callback] ) Example: Read the required document and get its _rev number. Output: { name: ‘Tom’, salary: 45000, experience: 3, _id: ‘100’, _rev: ‘1-99a7a70ec2a34678845637a16d57344f’ }{ name: 'Tom', salary: 45000, experience: 3, _id: '100', _rev: '1-99a7a70ec2a34678845637a16d57344f' } Use the _rev … Read more

Update Document in PouchDB

Update Document The _rev or revision marker is used to update a document in PouchDB which is generated when a PouchDB document is created and is changed whenever a change or update is made to the document. Example: Read the required document and get its _rev number. Output: { name: ‘Tom’, salary: 45000, experience: 3, … Read more