如何管理pouchdb和couchdb同步? [英] How to manage pouchdb and couchdb synchronization?

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

问题描述

存储多个用户数据的最佳方法是每个数据库每个用户。我正在使用相同的方法。

Best approach to store multiple user data is per user per database. I am using this same approach.

我在服务器上有沙发床,在移动应用程序上有pouchdb。我通过在pouchdb和couchdb中为用户创建单独的数据库来维护每个用户数据。那意味着我在沙发数据库中有多个数据库,在邮袋数据库中有一个数据库。

I have couchdb on server and pouchdb for mobile application. I am maintaining each user data by creating separate database for the user in pouchdb and couchdb. That.That means i have multiple database in couchdb and one database in pouchdb.

通常在sqlbase数据库中,用户数据存储在不同的表中。

usually in sqlbase database user data is store in different different table.

所以在nosql pouchdb中,我正在为每个表创建文档。

so in nosql pouchdb i am creating document for each table.

我面临的实际问题是:

每个数据库中都有一个文档来存储用户的交易。

I have one document in each database that stores the transactions of user.

客户交易在离线时存储在pouchdb中,并且当应用程序将在线事务同步到benchdb用户数据库并放入事务文档中时。

Client transaction is stored in pouchdb when he/she is offline and when application get on-line transaction sync to couchdb user database in to transaction document.

数据存储在事务文档中如下

data is stored in transaction document is as follows

{
  "_id":"transaction ",
  "_rev":"1-3e5e140d50bf6a4d873f0c0f3e3deb8c",
  "data":[
    {
      "transaction_id":"tran_1",
      "transaction_name":"approve item",
      "status":"Pending",
      "ResultMsg":""
    },
    {
      "transaction_id":"tran_2",
      "transaction_name":"approve item",
      "status":"Pending",
      "ResultMsg":""
    }]
}

所有这些事务都在服务器端执行,并且结果在这些文档中进行更新。无论何时执行任何新事务,我都会将其存储在数据属性。

All these transaction is performed on server side and result is updated in these document.when ever any new transaction performed i store it in transaction document in data attribute.

现在,我在pouch和benchdb中有1个事务,都意味着两者都是同步的。

Now i have 1 transaction in pouch and couchdb both means both are in sync.

现在当移动应用程序脱机时,它将执行存储在pouchdb交易文档中的脱机交易。

Now when mobile application is offline it perform offline transaction that is stored in pouchdb transaction doc.

,在服务器端,有1笔交易已成功更新。

and on server side that 1 transaction is updated to success.

现在,当应用程序进入联机状态并同步执行时,我丢失了服务器端的更改,最后交易文档中的数据被保存为客户端pouchdb。

Now when application goes to on-line and sync perform i am losing my server side changes and finally data in transaction doc is as client pouchdb.

在这里我丢失了服务器端数据。所以什么是好的方法,或者我怎么解决呢。

here i am losing server side data. so what is good approach or how can i solve it.


推荐答案

正在发生的事情是您对同一文档有冲突,因为它是由服务器以一种方式修改的,而由客户端以另一种方式修改的。一个有冲突的版本任意获胜,而另一个则失败。

What's happening is that you have conflicts to the same document, because it is modified in one way by the server and another way by the client. One conflicting version is winning arbitrarily, and the other is losing.

您可以解决冲突或(根据您的情况选择更合理的解决方案)为每个用户存储多个文档,而不是一个大文档。

You can either resolve the conflicts or (the more reasonable solution in your case) store multiple documents per user instead of one big document.

因为您只有一个数据库每个用户并不意味着您需要每个用户一个文档。 :)例如,您的文档可能是:

Just because you have one database per user doesn't mean you need to have one document per user. :) E.g your docs could be:

{_id: "Tran_1", status: "Pending"}
{_id: "Tran_2", status: "Pending"}
// etc.

这些文档将在客户端上创建一次,并在服务器上更新一次。没有冲突的可能性。小菜一碟!

These documents would be created once on the client and updated once on the server. No possibility of conflicts. Piece of cake!

这篇关于如何管理pouchdb和couchdb同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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