I have two mobile apps. Both with Phonegap and CouchBase Lite, and synchronized to the CouchBase server through Sync_Gateway.
I tried to emulate conflicts modifying the same doc (turning off connection to the server) from each app. It generates two different revisions on each mobile. Then I reestablished the connection to the server and the documents start to sync.
My problem is that I can’t see any conflict. The winner revision is now at the apps and at the server.
I suppose that I should see the conflict, with a conflict view, at the server but I don’t. The view always give me no results.
Couchbase Server doesn’t know about conflicts (or revisions at all, for that matter.) So a Couchbase Server map function will never see a _conflicts property the way it would in CouchDB. There isn’t currently a practical way to detect conflicts in a view, since the revision information is buried inside an opaque property (managed by Sync Gateway) inside the document.
In any case, it’s more common to deal with conflicts on the client side because resolving them often requires user interaction. Couchbase Lite has APIs for detecting and resolving conflicts; see the docs. If you’re using PhoneGap, you’d do it the CouchDB way, with a client-side view that checks the _conflicts property.
The _conflicts property should come back in documents when you query a view with the ‘include_docs’ and ‘conflicts’ set to true. This works ok for standard queries, but has the drawback to retreive the whole document for each query row just to have the the conflict information…
Would there be a way to emit this conflict info in the view’s map ? But it seems that we do not have access to the the _conflict property while emitting docs in a map function for a view on CouchBase Lite so how could we do that ?
After digging into the view code a bit and looking back into the CouchDB docs:
CouchDB puts a _conflicts property in the doc if the document is conflicted, but this doesn’t seem to be well documented; the only reference I found was in a wiki page: “Views only get the winning revision of a document. However they do also get a _conflicts member if there are any conflicting revisions.”
Couchbase Lite doesn’t support this. Probably it should, for compatibility.
However, CBL’s REST API does have include_conflicts and only_conflicts parameters on _all_docs queries, i.e. _all_docs?only_conflicts=true will make the query return only documents with conflicts, and the row values will include info about the conflicting revisions.
Yes this is what I figured out looking at the code . I wanted to know if there was an other way to do that exactly the same way CouchBD doese it. This way we could construct the view the way we want and return only the fields we need… Unfortunatly as you said, we do not have the meta parameter in the map function in couchbase lite.