同步MongoDB服务器数据到IndexedDB本地存储

时间:2022-08-13 22:51:15

I'm trying to evaluate using IndexedDB to solve the offline issue. It would be populated with data currently stored in a MongoDB database (as is).

我正在尝试评估使用IndexedDB来解决离线问题。它将使用当前存储在MongoDB数据库(as is)中的数据进行填充。

Once data is stored in IndexedDB, it may be changed on the MongoDB server and I need to propagate those changes. Is there any existing framework or Library to do somehting like this for Mongo. I already know about CouchDB/PouchDB and am not exploring those two.

一旦数据存储在IndexedDB中,它可能会在MongoDB服务器上被更改,我需要传播这些更改。有任何现有的框架或库可以为Mongo做这样的事情吗?我已经知道CouchDB/PouchDB,但我还没有研究这两个。

1 个解决方案

#1


0  

I haven't worked with IndexDB, but the design problem isn't that uncommon. My understanding of your app is that when the client makes the connection to MongoDB, you pull a set of documents down for local storage and disconnect. The client then can do things locally (not connected to the data server), and then push up the changes.

我没有使用过IndexDB,但设计问题并不罕见。我对您的应用程序的理解是,当客户端连接到MongoDB时,您将一组文档拉下来进行本地存储并断开连接。然后,客户端可以在本地(不连接到数据服务器)做一些事情,然后再进行更改。

The way I see it you've got to handle two general cases:

在我看来,你必须处理两种一般情况:

  1. when the MongoDB server is updated and breaks continuity with the client, the client will have to
    1. poll for the data (timer?) or
    2. 为数据(定时器?)或
    3. keep a websocket open to let notifications free-flow over the pipe
    4. 打开一个websocket,让通知在管道上*流动
  2. 当MongoDB服务器被更新并中断与客户端的连续性时,客户端将不得不轮询数据(定时器?)或保持websocket打开,以便通知在管道上*流动
  3. when the user needs to push changed data back up the pipe
    1. you can reconnect asynchronously, check for state changes, (resolving conflicts according to your business rules)
    2. 您可以异步重新连接,检查状态更改,(根据业务规则解决冲突)
    3. have a server side (light) interface for handling conflicts (depending on complexity of your app, comparing time stamps of state changes in MongoDB to IndexedDB updates should suffice)
    4. 有一个服务器端(light)接口来处理冲突(根据应用程序的复杂性,比较MongoDB中状态更改的时间戳和IndexedDB更新应该就足够了)
  4. 当用户需要推动改变异步数据备份管可以重新连接,检查状态改变,(根据你的业务规则)解决冲突有一个服务器端(光)接口来处理冲突(取决于应用程序的复杂性,比较时间戳的状态改变MongoDB IndexedDB更新应该足够了)

#1


0  

I haven't worked with IndexDB, but the design problem isn't that uncommon. My understanding of your app is that when the client makes the connection to MongoDB, you pull a set of documents down for local storage and disconnect. The client then can do things locally (not connected to the data server), and then push up the changes.

我没有使用过IndexDB,但设计问题并不罕见。我对您的应用程序的理解是,当客户端连接到MongoDB时,您将一组文档拉下来进行本地存储并断开连接。然后,客户端可以在本地(不连接到数据服务器)做一些事情,然后再进行更改。

The way I see it you've got to handle two general cases:

在我看来,你必须处理两种一般情况:

  1. when the MongoDB server is updated and breaks continuity with the client, the client will have to
    1. poll for the data (timer?) or
    2. 为数据(定时器?)或
    3. keep a websocket open to let notifications free-flow over the pipe
    4. 打开一个websocket,让通知在管道上*流动
  2. 当MongoDB服务器被更新并中断与客户端的连续性时,客户端将不得不轮询数据(定时器?)或保持websocket打开,以便通知在管道上*流动
  3. when the user needs to push changed data back up the pipe
    1. you can reconnect asynchronously, check for state changes, (resolving conflicts according to your business rules)
    2. 您可以异步重新连接,检查状态更改,(根据业务规则解决冲突)
    3. have a server side (light) interface for handling conflicts (depending on complexity of your app, comparing time stamps of state changes in MongoDB to IndexedDB updates should suffice)
    4. 有一个服务器端(light)接口来处理冲突(根据应用程序的复杂性,比较MongoDB中状态更改的时间戳和IndexedDB更新应该就足够了)
  4. 当用户需要推动改变异步数据备份管可以重新连接,检查状态改变,(根据你的业务规则)解决冲突有一个服务器端(光)接口来处理冲突(取决于应用程序的复杂性,比较时间戳的状态改变MongoDB IndexedDB更新应该足够了)