bry*_*yan 7 javascript couchdb cloudant pouchdb react-native
假设我有这三个文件:
{ "_id": "11111", "type": "template", "name": "person" }
{ "_id": "22222", "type": "template", "name": "place" }
{ "_id": "33333", "type": "template", "name": "thing" }
Run Code Online (Sandbox Code Playgroud)
我有一个云数据库,然后我有一个设备与该数据库的pouchDB同步.
这些是我做的步骤:
码
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;
});
Run Code Online (Sandbox Code Playgroud)
过滤器/模板
function (doc) {
if(doc.type == "template")
emit(doc._id);
}
Run Code Online (Sandbox Code Playgroud)
返回
{ "11111": true, "22222": true, "33333": true }
Run Code Online (Sandbox Code Playgroud)
我更新模板:云上的人.然后我再次更新它.因此,在没有同步到我的设备的情况下进行了2次修订.
我与我的设备同步.
返回
{"11111": true}
Run Code Online (Sandbox Code Playgroud)
_rev云中的相同模板将显示在设备上.意味着同步成功并且视图变得混乱.新代码
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));
})
Run Code Online (Sandbox Code Playgroud)
我开始相信这是一个错误,因为如果我破坏我的数据库并再次执行这些步骤,我可以重现这个问题.
在意识到你正在使用React Native之后,我认为这实际上与React Native中的PouchDB有关,这确实是一个错误。有一些关于这种行为的报告:
| 归档时间: |
|
| 查看次数: |
219 次 |
| 最近记录: |