Insert:

var data = {  
'name' : 'Ajeet',
'age' : 23,
'designation' : "Designer"
};
const insert = await blog.insert(data);
res.send(insert);

response:

{"ok": true,"id": "fac88d73661979cea68db9c3c2000a01","rev": "1-86ca9e7c60eee1d5644e846a699579b5"}

The response of CouchDB for this command contains 3 fields:

  • “ok”: It specifies that the operation is successful.
  • “id”: It stores the id of the document.
  • “rev”: This indicates the revision id. Every time you revise (update or modify) a document a _rev value will be generated by CouchDB. If you want to update or delete a document, CouchDB expects you to include the _rev field of the revision you want to change. When CouchDB accepts the change, it will generate a new revision number.

Get All data:

const q = {
selector: {},
fields: ['name','age','designation']
}
const getAll = await blog.find(q);
res.send(getAll.docs);

Get Single data:

const q = {
selector: {
_id: { '$eq': req.params._id } //where condition
},
fields: ['name','age','designation'] //show field
}
const singleblog = await blog.find(q);
res.send(singleblog.docs[0]);

selector:

selector: {
'$and': [
{ _id: { '$ne': req.body._id } },
{ name: { '$eq': req.body.name } }
]
}

Software Engineer