javascript - PouchDB + Conflict Resolution -
i have simple question hard topic:
how conflict resolution work in pouchdb?
i looked @ documentation, googling, didn't help. so, how handle conflict management in application using pouchdb?
here's how in couchdb, can directly translate pouchdb terms since apis same.
you fetch document, using conflicts=true
ask conflicts (get()
{conflicts:true}
in pouchdb):
http://localhost:5984/db1/foo?conflicts=true
you receive doc this:
{ "_id":"foo", "_rev":"2-f3d4c66dcd7596419c76b2498b3ba21f", "notgonnawork":"this second db", "_conflicts":["2-c1592ce7b31cc26e91d2f2029c57e621"] }
there conflict introduced database, , database's revision has (randomly) won. if used bi-directional replication, both databases provide same answer.
notice both revisions start "2-." indicates both second revision document, , both live @ same level of revision tree.
using revision id, fetch conflicting version (get()
{rev=...}
in pouchdb:
http://localhost:5984/db1/foo?rev=2-c1592ce7b31cc26e91d2f2029c57e621
you receive:
{ "_id":"foo", "_rev":"2-c1592ce7b31cc26e91d2f2029c57e621", "notgonnawork":"this first database" }
after presenting 2 conflicting versions user, can put
(put()
) third revision on top of both of these. third version can combine results, choose loser, or whatever want.
advanced reading:
Comments
Post a Comment