gpt4 book ai didi

PouchDB on Put 方法将返回 "Document update conflict"

转载 作者:行者123 更新时间:2023-12-03 09:00:32 25 4
gpt4 key购买 nike

PouchDB 无法更新 CouchDB 条目。它返回“文档更新冲突。”

我在pouchdb文档上阅读了冲突问题,我尝试了很多场景,但总是相同的结果。409文档更新冲突

这是最后一个代码:

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);
});
});
}
});

我尝试了这个解决方案(在 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);
}
});
};

您知道如何更新类别的名称吗?

本地名称属性将被替换! (在pouchdb中,但不会更新到couchdb!)

最佳答案

当您尝试更新没有 _rev 的文档或文档的修订版已过时(已从修订版树中删除)时,就会发生冲突。

因此,在没有有效 _rev 的情况下进行更新。您可以将选项 force 设置为等于 true

const respond = wait db.put(doc, {force: true})

了解有关冲突的更多信息 here :

Note: to limited conflicting, limited change your document by small pieces

关于PouchDB on Put 方法将返回 "Document update conflict",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50871113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com