At whatever point, we make a record in PouchDB, another field _rev is created, and it is known as correction marker. The _rev's worth is a one of a kind arbitrary number, each time we make changes to the record the estimation of _rev is changed.
You can refresh a current archive in PouchDB utilizing the (_rev). To do as such, above all else recover the _rev estimation of the report we need to refresh. Presently, place the substance that are to be refreshed alongside the recovered _rev esteem in another record, lastly embed this report in PouchDB utilizing the put() technique.
Example
Expect we have a report in PouchDB with id 001 which has subtleties of an individual. To refresh this record, we ought to have its fire up number. Consequently, to recover the substance of the report the accompanying code is utilized.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Reading the contents of a Document
db.get('001', function(err, doc) {
if (err) {
return console.log(err);
} else {
console.log(doc);
}
});
On executing the above code, you will get the accompanying yield.
{
_id: '001',
_rev: '3-552920d1ca372986fad7b996ce365f5d',
name: 'Raju',
age: 23,
designation: 'Designer'
}
Presently, utilizing the _rev you can refresh the estimation of the key "age" to 26, as demonstrated in the accompanying code.
//Requiring the package
var PouchDB = require('PouchDB');
//Creating the database object
var db = new PouchDB('my_database');
//Preparing the document for update
doc = {
age: 26,
_rev: '3-552920d1ca372986fad7b996ce365f5d',
}
//Inserting Document
db.put(doc);
//Reading the contents of a Document
db.get('001', function(err, doc) {
if (err) {
return console.log(err);
} else {
console.log(doc);
}
});
Save the above code in a document with the name Update_Document.js. Open the order incite and execute the JavaScript document utilizing hub as demonstrated beneath.
C:\Pouch_Examples>node Update_Document.js
This updates the substance of the given record that exists in the data set named my_database which is put away locally. The accompanying message is shown on the comfort.
{
name: 'Raju',
age: 26,
designation: 'Designer',
_id: '001',
_rev: '2-61b523ccdc4e41a8435bdffbb057a7a5'
}
Updating a Document in a Remote Database
You can likewise refresh a current archive in an 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 information base in CouchDB, which contains the report that will be refreshed.
Example
Assume there is a data set named my_database in the CouchDB worker. At that point, in the event that you confirm the rundown of data sets in CouchDB utilizing the URL http://127.0.0.1:5984/_utils/index.html you will get the accompanying screen capture.
By tapping on the data set named my_database, you can see the accompanying screen capture. Here, you can see that this data set contains a record with id 001.
Following is an illustration of refreshing the age of the archive having id as "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');
//Preparing the document for update
doc = {
age: 26,
_rev: '3-552920d1ca372986fad7b996ce365f5d',
}
//Inserting Document
db.put(doc);
//Reading the contents of a Document
db.get('001', function(err, doc) {
if (err) {
return console.log(err);
} else {
console.log(doc);
}
});
Save the above code in a document with the name Remote_Update_Document.js. Open the order provoke and execute the JavaScript document utilizing hub as demonstrated underneath.
C:\PouchDB_Examples >node Remote_Update_Document.js
This updates the substance of the given record that exists in the data set named my_database which is put away in CouchDB. The accompanying message is shown on the support.
{
_id: '001',
_rev: '2-b9640bffbce582c94308905eed8bb545',
name: 'Raju',
age: 26,
designation: 'Designer'
}
