Let's say I have these three documents:
{ "_id": "11111", "type": "template", "name": "person" }
{ "_id": "22222", "type": "template", "name": "place" }
{ "_id": "33333", "type": "template", "name": "thing" }
I have a cloud database and then I have a device with pouchDB syncing from that database.
These are the steps that I do:
- I sync both databases together. So now I have the most recent versions of this document on my device.
- I run the below query and I get back all three templates like so:
Code
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;
});
filters/templates
function (doc) {
if(doc.type == "template")
emit(doc._id);
}
return
{ "11111": true, "22222": true, "33333": true }
I update template: person on cloud. And then I update it again. So 2 revisions have gone by without syncing to my device.
I sync with my device.
- Now when I run the same query and I only get back the document I edited. Which is weird because I haven't touched any of the other documents. The same view returns the expected results on the cloud but not on the device.
return
{"11111": true}
- If I do the following code however, all templates come back as normal and the same
_rev
from the cloud show up on the device. Meaning the sync was successful and view is getting confused.
new code
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));
})
I'm starting to believe this is a bug because if I destroy my database and do these steps again, I can reproduce this issue.
_rev
on the object – HypnologyFauxton
works if you were to edit the document. The issue is not in how I am updating the document because the filter works on the dashboard. – Drifter{'11111': true, '22222': true, '33333': true}
. – Provencefilters/templates
seems to be a view called 'templates' in a design doc called 'filters', not an actual filter, right?db.query
uses previously saved views: pouchdb.com/api.html#query_database - am I correct with that? – Provencefilters
, another thing I failed to mention nice catch. From my experience,db.query
has been using my defined view (views sync like the rest of the documents). Even if I use a newly defined view function (that's the same), I get the same issue – Drifter