简体   繁体   English

PouchDb / CouchDb冲突问题

[英]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. 我正在使用带有CouchDb后端的PouchDb,并在网站启动时在客户端上,我正在插入一个文档(在数据库同步之前)与服务器中的文档相同的“id”。

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. 这很好,因为它是相同的文件但是PouchDb文件是_rev:1而couchDb文件可能是_rev:2,当我的PouchDb确实同步并且我试图再次获取文档时我会遇到冲突。

So I then have on the client: 所以我在客户端上:

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

But the correct version is actually _rev: 1 (since this was the version the client first created). 但正确的版本实际上是_rev:1(因为这是客户端首次创建的版本)。

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. 首先,创建具有不同ID的文档。 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. 例如,如果您的客户端应用程序知道修订版1是正确的,那么当您看到有冲突的修订版时,请删除除正确修订版之外的所有修订版。 Those delete operations will replicate to CouchDB and soon you will have only the one, correct revision. 那些删除操作将复制到CouchDB,很快您将只有一个正确的修订版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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