Couchbase-Lite Data Disappears after an Update Operation

I currently am able to Create, Retrieve and Delete documents with my current couchbase-lite setup with Android no problem. The issue I am having is that if I update a “workout” on one device, when I move to another device and hit refresh and run this query again the update disappears on the other device. Any idea why the workout would not update on both devices? It only updates on the device where I made the update

Here is my Query Code:

public static Query getWorkouts(Database database) {

    View view = database.getView("workout/workouts");

    if(view.getMap() == null) {
        view.setMap(new Mapper() {
            @Override
                public void map(Map<String, Object> document, Emitter emitter) {

                if (document.get("type") != null) {
                    if (document.get("type").equals("workout8")) {
                        emitter.emit("aaaaa", document.get("_id"));
                        int a = 0;
                    }
               }
            }
        }, "44");
    }
    Query query = view.createQuery();
    query.setIndexUpdateMode(Query.IndexUpdateMode.AFTER);
    return query;
}

Maybe a silly question, but you are running replication right? Is the update in question visible on Sync Gateway?

If I go to couchbase server the update will be present there yes @borrrden

Also if I kill the app and re-open it the updated item will be loaded into the app just fine

The only thing I can think from that is that you set the index update mode to “after” meaning it will give whatever results it has already immediately, and then asynchronously update the results later meaning that the first query will have outdated results until the index is then subsequently updated.

1 Like

Before and After still both cause the same issue unfortunately

Found the issue. It was a problem with the library I was using to parse the couchbase document. It was unrelated to my query code as you rightly diagnosed. Thanks for the help. This was a weird one

1 Like