This is my Couch DB Document
{"people": [{"id": 1,"dept_id": 1,"user": "A",},{"id": 2,"dept_id": 1,"user": "B",},{"id": 3,"dept_id": 1,"user: "C",}]}
User A Changed his dept_id to 3 in pouch DB
{"people": [{"id": 1,"dept_id": 3,"user": "A",},{"id":2 ,"dept_id": 1,"user": "B",},{"id": 3,"dept_id": 1,"user": "C",}]}
User B Changed his dept_id to 4 in pouch DB
{"people": [{"id": 1,"dept_id": 1,"user": "A"},{"id":2 ,"dept_id": 4,"user": "B"},{"id": 3,"dept_id": 1,"user": "C"}]}
If A and B replicate the data to Couch DB , The Couch Document updated with
{"people": [{"id": 1,"dept_id": 1,"user": "A"},{"id":2 ,"dept_id": 4,"user": "B"},{"id": 3,"dept_id": 1,"user": "C"}]}
But my expected Output
{"people": [{"id": 1,"dept_id": 3,"user": "A"},{"id":2 ,"dept_id": 4,"user": "B"},{"id": 3,"dept_id": 1,"user": "C"}]}
I have tried this to update the pouch Db
var mydb = new PouchDB('localPouchDb',{revs_limit: 1, auto_compaction: true});db.upsert('people ', function myDeltaFunction(doc) { doc.dept_id=4 return doc;}).then(function () { console.log('success')}).catch(function (err) { console.log(err)});
I have tried this to replicate the couch Db with pouch by
var remoteDB = new PouchDB('remote address',{revs_limit: 1, auto_compaction: true});db.replicate.to(remoteDB);
I have searched in some links and they said that
it is not possible to update single field , replicate replace the whole document with pouch db
https://www.tutorialspoint.com/couchdb/couchdb_updating_a_document.htm
How to update a document's record/field in couchdb
You can't do it. Because CouchDb allows save a data as JSON records. So last updated record will be add in couchDB.
If you want to do it for your specific functionality, Make it as separate document
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With