简体   繁体   中英

PouchDb / CouchDb conflict issue

I'm using PouchDb with a CouchDb backend and on the client upon the website starting up, I'm inserting a document (before the database syncs) with the same 'id' as a document in the server.

This this is fine as it's the same document but as the PouchDb document is _rev: 1 and the couchDb document might be say _rev: 2, when my PouchDb does sync and I try to get the document again I get conflicts.

So I then have on the client:

{ _id: 'mydoc', _rev: '1-xxxxxxxxx' } AND { _id: 'mydoc', _rev: '2-xxxxxxxxx' }

But the correct version is actually _rev: 1 (since this was the version the client first created).

How do I correctly fix this problem on the client so that it fixes the conflict?

You have two choices:

First, create documents with different IDs. It depends on the application; perhaps this is not possible or not appropriate for your situation.

Second, you need code to delete the "wrong" revision of the document. (You can do this on the client, or on the server. In both cases, the update will replicate to the other system.)

For example, if your client application knows that revision 1 is correct, then when you see conflicting revisions, delete all of them except the correct one. Those delete operations will replicate to CouchDB and soon you will have only the one, correct revision.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM