Couchdb在线下线同步 [英] Couchdb online offline synchronisation

查看:122
本文介绍了Couchdb在线下线同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个.NET应用程序,它将有一个本地CouchDB实例(所有数据都写入其中)和一个中央CouchDB(本地CouchDB同步到其中).困难在于,将有多个客户端将在不同点与数据库同步(并且可能会编辑现有数据,从而产生冲突).互联网连接将不一致,因此大部分数据将在离线状态下创建/编辑.

I'm building a .NET application which will have a local CouchDB instance where all data is written to, and a central CouchDB where the local CouchDB is synchronised to. The difficulty is that there will be multiple clients which will synchronise with the database at different points (and could edit existing data, creating conflicts). The internet connection will not be consistent, so consequently the majority of data will be created/ edited while offline.

我相信CouchDB会固有地处理此问题,但是我很难确定我应该使用_changes还是_replicator功能-或两者结合使用.非常感谢您提供一些有关如何处理这种情况的提示.

I believe that CouchDB handles this inherently, however I'm having difficulty figuring out whether I should be working with the _changes or _replicator functionality - or a combination. Would very much appreciate a few pointers on how to handle this scenario.

推荐答案

Couchdb将为您检测到冲突,但是,您有责任处理这些冲突.以下是有关 couchdb冲突模型

Couchdb will detect conflicts for you, however it leaves the responsibility of handling those conflicts to you. Here are details on couchdb conflict model and some ways to design you application for replication.

_changes不是复制的好方法,因为它仅提供对给定文档的最新更改.因此,如果使用更改提要复制到新创建的数据库,则将丢失一些较旧的更改.并且您将必须手动执行诸如_replication为您完成的更新文档之类的操作. _replication还有一些好处,例如可以创建目标数据库(如果尚不存在).

_changes is not a good way to replicate because it only provides recent changes to a given document. So if you replicate using a changes feed to a database that is newly created you will loose some of the older changes for it. And you will have to manually perform the operations like updating documents that _replication does it for you. _replication also has some goodies like the ability to create a target database if it does not already exist.

即使您正在听continuous更改的提要,也不能保证对文档的每次更新都将返回.

Even if you are listening to continuous feed of changes not every update to the document is guaranteed to be returned.

按应用时间顺序返回对数据库中文档所做的更改的排序列表,可以从数据库的_changes资源中获取.确保仅提供给定文档的最新更改,例如,如果文档已添加字段然后又删除了字段,则检查更改的API客户端不一定会收到添加文档的中间状态.

Returns a sorted list of changes made to documents in the database, in time order of application, can be obtained from the database’s _changes resource. Only the most recent change for a given document is guaranteed to be provided, for example if a document has had fields added, and then deleted, an API client checking for changes will not necessarily receive the intermediate state of added documents.

因此,如果您打算跨各种设备复制数据,则要使用replication.

So replication is the way to go if you plan on replicating the data across various devices.

这篇关于Couchdb在线下线同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆