admin管理员组

文章数量:1023097

I have a really simple question about hard topic:

How does conflict resolution work in PouchDB?

I looked at the documentation, as well as quickly googling, but it didn't help. So, how to do I handle conflict management in my application which is using PouchDB?

I have a really simple question about hard topic:

How does conflict resolution work in PouchDB?

I looked at the documentation, as well as quickly googling, but it didn't help. So, how to do I handle conflict management in my application which is using PouchDB?

Share Improve this question edited Mar 13, 2016 at 13:34 Jonathan Hall 80k19 gold badges160 silver badges204 bronze badges asked Jun 27, 2014 at 11:16 dimko1dimko1 8727 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Here's how you do it in CouchDB, which you can directly translate into PouchDB terms since the APIs are exactly the same.

You fetch a document, using conflicts=true to ask for conflicts (get() with {conflicts:true} in PouchDB):

http://localhost:5984/db1/foo?conflicts=true

You receive a doc like this:

{
"_id":"foo",
"_rev":"2-f3d4c66dcd7596419c76b2498b3ba21f",
"notgonnawork":"this is from the second db",
"_conflicts":["2-c1592ce7b31cc26e91d2f2029c57e621"]
}

There is a conflict introduced from another database, and that database's revision has (randomly) won. If you used bi-directional replication, both databases will provide this same answer.

Notice that both revisions start with "2-." This indicates that they are both the second revision to the document, and they both live at the same level of the revision tree.

Using the revision ID, you fetch the conflicting version (get() with {rev=...} in PouchDB:

http://localhost:5984/db1/foo?rev=2-c1592ce7b31cc26e91d2f2029c57e621

You receive:

{
"_id":"foo",
"_rev":"2-c1592ce7b31cc26e91d2f2029c57e621",
"notgonnawork":"this is from the first database"
}

After presenting the two conflicting versions to the user, you can then PUT (put()) a third revision on top of both of these. Your third version can bine the results, choose the loser, or whatever you want.

Advanced reading:

  • The CouchDB docs on conflict resolution
  • The CouchDB wiki page on conflicts.
  • Understanding CouchDB Conflicts by Jan Lenhardt

I have a really simple question about hard topic:

How does conflict resolution work in PouchDB?

I looked at the documentation, as well as quickly googling, but it didn't help. So, how to do I handle conflict management in my application which is using PouchDB?

I have a really simple question about hard topic:

How does conflict resolution work in PouchDB?

I looked at the documentation, as well as quickly googling, but it didn't help. So, how to do I handle conflict management in my application which is using PouchDB?

Share Improve this question edited Mar 13, 2016 at 13:34 Jonathan Hall 80k19 gold badges160 silver badges204 bronze badges asked Jun 27, 2014 at 11:16 dimko1dimko1 8727 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Here's how you do it in CouchDB, which you can directly translate into PouchDB terms since the APIs are exactly the same.

You fetch a document, using conflicts=true to ask for conflicts (get() with {conflicts:true} in PouchDB):

http://localhost:5984/db1/foo?conflicts=true

You receive a doc like this:

{
"_id":"foo",
"_rev":"2-f3d4c66dcd7596419c76b2498b3ba21f",
"notgonnawork":"this is from the second db",
"_conflicts":["2-c1592ce7b31cc26e91d2f2029c57e621"]
}

There is a conflict introduced from another database, and that database's revision has (randomly) won. If you used bi-directional replication, both databases will provide this same answer.

Notice that both revisions start with "2-." This indicates that they are both the second revision to the document, and they both live at the same level of the revision tree.

Using the revision ID, you fetch the conflicting version (get() with {rev=...} in PouchDB:

http://localhost:5984/db1/foo?rev=2-c1592ce7b31cc26e91d2f2029c57e621

You receive:

{
"_id":"foo",
"_rev":"2-c1592ce7b31cc26e91d2f2029c57e621",
"notgonnawork":"this is from the first database"
}

After presenting the two conflicting versions to the user, you can then PUT (put()) a third revision on top of both of these. Your third version can bine the results, choose the loser, or whatever you want.

Advanced reading:

  • The CouchDB docs on conflict resolution
  • The CouchDB wiki page on conflicts.
  • Understanding CouchDB Conflicts by Jan Lenhardt

本文标签: javascriptPouchDBConflict ResolutionStack Overflow