Help with conflicts in CBL Android


#1

I’m looking into a weird conflict problem I get in Android from time to time (doesn’t appear to happen in IOS).

How do I get the conflicts information using the REST API?


#2

@nick-couchbase

Try this:

http://(host):(port)/(db_name)/_changes?include_docs=true&conflicts=true

Source: http://developer.couchbase.com/documentation/mobile/1.2/develop/references/couchbase-lite/rest-api/database/get-changes/index.html


#3

Is there a way to get only documents that have conflicts ?


#4

Yup,

// Let's find the documents that have conflicts so we can resolve them:

Query query = database.createAllDocumentsQuery();

query.setAllDocsMode(Query.AllDocsMode.ONLY_CONFLICTS);

QueryEnumerator result = query.run();

for (Iterator<QueryRow> it = result; it.hasNext(); ) {
    QueryRow row = it.next();
    if (row.getConflictingRevisions().size() > 0) {
        Log.w("MYAPP", "Conflict in document: %s", row.getDocumentId());
        beginConflictResolution(row.getDocument());
    }
}

Source: http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/couchbase-lite/native-api/query/index.html

THE OG method stems from here:

function(doc) {
  if(doc._conflicts) {
    emit(doc._conflicts, null);
  }
}

Source: http://guide.couchdb.org/draft/conflicts.html


#5

Thanks. I’m using the rest_api and the only_conflicts parameter isn’t documented. I recall when I tried it it didn’t seem to work on android. But I’ll try the view method, that looks good.