这是我的Couch DB文件
{"people": [{"id": 1,"dept_id": 1,"user": "A",},{"id": 2,"dept_id": 1,"user": "B",},{"id": 3,"dept_id": 1,"user: "C",}]}
用户A在邮袋DB中将其dept_id更改为3
{"people": [{"id": 1,"dept_id": 3,"user": "A",},{"id":2 ,"dept_id": 1,"user": "B",},{"id": 3,"dept_id": 1,"user": "C",}]}
用户B在邮袋DB中将其dept_id更改为4
{"people": [{"id": 1,"dept_id": 1,"user": "A"},{"id":2 ,"dept_id": 4,"user": "B"},{"id": 3,"dept_id": 1,"user": "C"}]}
如果A和B将数据复制到Couch DB,则Couch文档更新为
但是我的预期输出
我已经尝试过更新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)});
我已经尝试过用沙发袋复制沙发Db
var remoteDB = new PouchDB('remote address',{revs_limit: 1, auto_compaction: true});db.replicate.to(remoteDB);
我搜索了一些链接,他们说
https://www.tutorialspoint.com/couchdb/couchdb_updating_a_document.htm
How to update a document's record/field in couchdb
最佳答案
你做不到因为CouchDb允许将数据另存为JSON记录。因此,最后更新的记录将添加到bedDB中。
如果要针对特定功能执行此操作,请将其作为单独的文档