PouchDB on Put 方法将返回“文档更新冲突”

Dab*_*gab 2 pouchdb

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!)

Win*_*ing 5

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

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

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

在这里阅读有关冲突的更多信息:

注意:为了限制冲突,限制对文档进行小块更改