gpt4 book ai didi

javascript - 更新文档时的 pouchDB query() 错误

转载 作者:数据小太阳 更新时间:2023-10-29 04:50:16 25 4
gpt4 key购买 nike

假设我有这三个文件:

{ "_id": "11111", "type": "template", "name": "person" }
{ "_id": "22222", "type": "template", "name": "place" }
{ "_id": "33333", "type": "template", "name": "thing" }

我有一个云数据库,然后我有一个从该数据库同步 pouchDB 的设备。

这些是我执行的步骤:

  1. 我将两个数据库同步在一起。所以现在我的设备上有此文档的最新版本。
  2. 我运行以下查询,然后像这样取回所有三个模板:

代码

var template_obj = {};

return device_db.query('filters/templates')
.then((templates) => {
for (let t of templates.rows) templates_obj[t.id] = true;
return templates_obj;
});

过滤器/模板

function (doc) {
if(doc.type == "template")
emit(doc._id);
}

返回

{ "11111": true, "22222": true, "33333": true }
  1. 我更新模板:云端人物。然后我再次更新它。所以 2 次修订没有同步到我的设备。

  2. 我与我的设备同步。

  3. 现在,当我运行相同的查询时,我只取回了我编辑过的文档。这很奇怪,因为我没有触及任何其他文件。相同的 View 在云端返回预期结果,但在设备上却没有。

返回

{"11111": true}
  1. 但是,如果我执行以下代码,所有模板都会正常返回,并且来自云的相同 _rev 会显示在设备上。这意味着同步成功并且 View 变得困惑。

新代码

return device_db.allDocs({conflicts: true})
.then((data) => {
for (let d of data.rows) {
if(d.doc.type == "template") {
templates_obj[d.doc._id] = true;
}
}
return templates_obj;
}).catch((err) => {
console.log(JSON.stringify(err));
})

我开始相信这是一个错误,因为如果我破坏我的数据库并再次执行这些步骤,我可以重现这个问题。

最佳答案

发现你用的是React Native,我觉得这其实和React Native中的PouchDB有关,确实是个bug。有几个关于这种行为的报告:

关于javascript - 更新文档时的 pouchDB query() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50587136/

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