Hi,
I am getting problems in retrieving documents from cbl. i’m able to add documents successfully. it returns id of newly created doc properly. (that’s how you get confirmation of successful addition. right?) but when i run my getAllDoc query, it always returns old data. ( meaning it gives some days old data. not the newly added docs). and this happens only in some devices. what could be the reason?
Hi @ankitsaliya,
Which platform are you using (iOS, Android, Windows?) and which version of Couchbase Lite? That might help find if there’s a related issue on GitHub.
James
Hi @jamiltz
It’s Android. Version i’m using is 1.3.1 currently.
Thanks,
@ankitsaliya can you post code snippets? You talk about creating new docs, but getting old data. Maybe there’s some confusion between updating existing docs and creating new ones?
When you say this happens on some devices, but not others, can you list some of the platforms and versions?
Hod
@hod.greeley
Hi,
Oh wait. maybe I was not clear. let me describe situation again. I didnt say old data of same document. I said old data of db. (so no issue with updation) meaning, When I run my allDoc query, it is only returning data upto some specific point.so all docs added after that point are gone. I tried adding more docs, it added successfuly but on fetching it will return only upto that specific point
My create doc code:
if (database != null && database.isOpen()) {
Document doc = database.createDocument();
doc.putProperties(docContent);
return doc.getId();
}
My getAllDoc query:
Query query = database.getView(VIEW_TIMESTAMP).createQuery();
query.setAllDocsMode(Query.AllDocsMode.ALL_DOCS);
query.setDescending(true);
QueryEnumerator result = null;
try {
result = query.run();
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Iterator<QueryRow> it = result;
if (it != null) {
for (it = result; it.hasNext(); ) {
QueryRow row = it.next();
Document doc = row.getDocument();
logDocs.add(doc);
}
}
And yes. I noticed this on couple of samsung devices. (One with adnroid 4.1 and one with 5.0) also on one Yureka device ( with android 6.0)
@ankitsaliya Ah, I think I see the problem. You want to start with an allDocs query. I don’t believe taking a VIew and setting the allDocsMode on it works.
Take a look at how the query is done here: http://developer.couchbase.com/documentation/mobile/current/develop/guides/couchbase-lite/native-api/query/index.html#all-documents-queries
@hideki is seems like an issue that you can call setAllDocsMode on a query obtained from a View. What do you think?
Hod
@hod.greeley
I get your point. but then how do i get all documents on a particular view? documentation (the one in given link ) says it runs on imaginary view. but i want to run query on my view assuming it will be faster than imaginary view. please throw some light if i’m wrong.
And also, then how that snippet works fine in majority of devices?
Thanks,
Ankit
@ankitsaliya
A Query returns all documents from a View by default. See this for more details (the beginning of the paragraph tells you what the default order is): http://developer.couchbase.com/documentation/mobile/current/develop/guides/couchbase-lite/native-api/query/index.html#creating-and-configuring-queries
I don’t know why this would work on most devices.
Views are static indexes created by processing documents through the associated map/reduce functions. The only way you should get all documents once you’ve restricted your query to a view is if all the docs have some output from the map function for that View. But since it wasn’t built to work the way you were using it, there may be some unexpected interaction going on. Hard to say.
Hod
Just take out the call to query.setAllDocsMode
.