PouchDB 无法更新 CouchDB 条目。它返回“文档更新冲突”。
我在 pouchdb 文档上阅读了冲突问题,我尝试了很多场景,但总是相同的结果。
409 Document update conflict
所以这是最后一段代码:
docs.forEach((element, index) => {
if (categoriesData[element._id] != null){
pouchdatabase.get(element._id).then(function (origDoc) {
// var doc = element;
// doc._rev = origDoc._rev;
// doc.name = categoriesData[element._id].newName;
// var doc = {
// _id: element._id,
// _rev: origDoc._rev,
// name: categoriesData[element._id].newName
// };
pouchdatabase.put( {
_id: element._id,
_rev: origDoc._rev,
name: categoriesData[element._id].newName
}).then(function (response) {
console.log('updated');
}).catch(function (err) {
console.log(err);
});
});
}
});
Run Code Online (Sandbox Code Playgroud)
我尝试了这个解决方案(在 Pouchdb github 上找到),但同样的错误......
var retryUntilWritten = function (doc) {
return pouchdatabase.get(doc._id).then(function (origDoc) {
doc._rev = origDoc._rev;
return pouchdatabase.put(doc);
}).catch(function (err) {
if (err.status === 409) {
return retryUntilWritten(doc);
} else { // new doc
return pouchdatabase.put(doc);
}
});
};
Run Code Online (Sandbox Code Playgroud)
您知道如何更新该name类别吗?
本地名称属性将被替换!(在 pouchdb 中,但不会更新到 couchdb!)