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

Read Document in PouchDB

Read Document To retrieve the document created in PouchDB, the db.get() method is used. Syntax: db.get(document, callback) Example: Create a file named “ReadDocument.js” within a folder named “Examples”. Add the below code to the file. ReadDocument.js: var PouchDB = require(’PouchDB’); var db = new PouchDB(’Example_Database’); db.get(’100′, function(err, doc) { if (err) { return console.log(err); } … Read more

Create Document in PouchDB

Create Document To create a document in PouchDB, the db.put() method is used. Syntax: db.put(document, callback) Example: Create a file named “NewDocument.js” within a folder named “Examples”. Add the below code to the file.NewDocument.js: var PouchDB = require(’PouchDB’); var db = new PouchDB(’Example_Database’); doc = { _id: ‘100’, name: ‘Tom’, salary: 45000, experience: 3 } … Read more

Delete Database in PouchDB

PouchDB Delete Database To delete a database in PouchDB, the db.destroy() method is used. Syntax: db.destroy() Example: Open Node.js command prompt. Create a file named “DeleteExample.js” within a folder named “Examples”. Add the below code to the file. DeleteExample.js: var PouchDB = require(’PouchDB’); var db = new PouchDB(’Example_Database’); db.destroy(function (err, response) { if (err) { return … Read more

Database Info in PouchDB

Database Info To get the information about a PouchDB database, the info () method is used in PouchDB. Syntax: db.info([callback]) Example: Create a file named “InfoExample.js” within a folder name “Examples”. Add the below code to the file. InfoExample.js var PouchDB = require(’PouchDB’); var db = new PouchDB(’Example_Database’); db.info(function(err, info) { if (err) { return … Read more

PouchDB Create Database

PouchDB Create Database PouchDB constructor is used in Node.js command prompt to create a database in PouchDB. Syntax: new PouchDB(Database_name) Example: Open Node.js command prompt. Create a file named “Example.js” within a folder named “Examples”. Add the below code to the file.   Example.js: var PouchDB = require(‘PouchDB’); var x = new PouchDB(‘Example_Database’); console.log (“Database … Read more

Install PouchDB

Steps to Install PouchDB Firstly, install Node.js for using PouchDB with Node console. Download and install npm. Install PouchDB by executing the below code on Node.js command prompt. npm install pouchdb Install PouchDB Server by executing the below code on Node.js command prompt. npm install -g pouchdb-server Set a port to run PouchDB: pouchdb-server –port 5000 … Read more

Node.js CouchDB Tutorial

Node.js CouchDB To connect Node.JS with CouchDB follow the below steps: Open the C drive. Create a folder named “Students” within an already created folder “Project”. Open the command prompt. Go to the location. Start npm init. Create a file named “app.js”. Add the below code to the file. Here, the entry point is app.json. … Read more