3

I am developing a prototype website that works offline that utilises Pouch DB so that it syncs back up to a CouchDB on a server when it goes online.

The Pouch DB conflicts guide says:

To resolve the conflict, you simpy put() a new revision on top of the current winner.

How do you do this? I have the tried the following functions but neither work as expected:

function (current, chosen) {
    chosen._rev = current._rev;
    chosen._conflicts = [];
    db.put(chosen);
};

function (chosen) {;
    db.put(chosen);
};

The top function takes two documents:

  • The document that is the current winner
  • The document the user has selected to become the new winner.

I've read in some places (like here) that deleting the losing conflicts is necessary but I would rather not delete anything if possible, and the Pouch DB guide has no mention of this.

Community
  • 1
  • 1
Connel
  • 1,844
  • 4
  • 23
  • 36

1 Answers1

7

You're right; you need to delete the losing conflicts (as unsavory as that sounds). I made a mistake when I wrote the guide; the conflicts will still exist unless you delete them.

By the way, deleting the conflicting revisions just means adding a "tombstone" on top of them. So really nothing is being "deleted" unless you explicitly compact your database. This is the case with both PouchDB and CouchDB.

Edit: I fixed the docs. In any case, could you please update the guide to reflect that fact that you need to delete any unwanted conflicting revisions? We love pull requests, especially from folks who have dealt with this kind of stuff first-hand! :) The document that needs to be modified is this one.

nlawson
  • 11,510
  • 4
  • 40
  • 50
  • To be honest I'm struggling to get this to work myself, maybe if I get it working I'll consider updating the guide, but to be honest I imagine someone who actually knows what they are talking about should be updating the docs! – Connel Dec 01 '14 at 10:27
  • I'm also confused as I keep finding stackoverflow answers wirrten by yourself that contradicts this (like http://stackoverflow.com/a/24190728/310098) is there a definitive guide anywhere on how this is done? Another thing that has me confused is that if I "get" a losing revision with {conflicts:true} it lists itself as its only conflict. Is this expected behaviour? Thanks – Connel Dec 01 '14 at 13:06
  • So if I'm ever wrong in my comments, please call me out on it. :) As for a definitive guide: yes, there is the [CouchDB one](http://guide.couchdb.org/draft/conflicts.html). Keep in mind that PouchDB implements CouchDB down to the smallest detail, so except in very rare cases you can just use their docs. – nlawson Dec 01 '14 at 17:23