I have been using Couchbase lite 1.4.1 without problems (other than performance issues) and saw the announcement of couchbase lite 2.0 for android, and since I deeply dislike views and prefer the new real-query approach Couchbase lite is taking I’m trying to migrate everything in my app from v1.4.1 to v2.0.0.
I use this code to save data:
Map<String, Object> objectProperties= new HashMap<String, Object>(){
{
put("contact", new ObjectMapper().convertValue(getLead(), new TypeReference<Map<String, Object>>() {}));
}
};
MutableDocument document = new MutableDocument(objectProperties);
MyDatabaseController.getDatabase().save(document);
I’m using jackson to convert my Object to Map since for some reason I cant use a POJO like it was in the 1.4.1 version.
And I’m using this code to retrieve (or attempt to) the saved data
Nothing looks obviously wrong, but I’d like to think this is too simple of a case for it to be a bug in the library. I imagine that the real answer is 3) Something else is going on besides what is shown here. Perhaps MyDatabaseController returning differing database instances, for example?
That is exactlyl what I thought, the use case is too simple for it to be a library problem, this is pretty much the example they have in the documentation.
I’ll continue trying. Do you think the replication could have an impact over this use case? Somehow messing with the Database data?
Can you try same code but first REMOVE the if check on size?
In other words comment out the following block. (Explanation follows.)
In my experience with the beta (have not looked at final version sources), checking allResults.size() causes an enumeration on the resultset, and unlike version 1.x where you can RESET a result set’s enumeration (index back to 0), with 2.x you cannot.
In other words getting the size (this way) from the resultset and using the resultset ‘normally’ is mutually exclusive.
Also, for testing, also select the document id (in the select clause) and log it to console in the resultset loop. Just to rule out any unrelated problems with document props and/or gui.
-nat (not a cb employee.)
You are right. That is the problem. I was checking the size of the results and reaching the end of the iterator.
When I made it work I removed the zero-check and didnt think to much of it, I just tested to see if that is the problem and it is. Now is working as intended. Thank you all for your help.