gpt4 book ai didi

javascript - 如何判断 Meteor minimongo 何时与 mongo 服务器同步

转载 作者:可可西里 更新时间:2023-11-01 09:55:13 27 4
gpt4 key购买 nike

我有一个 Meteor 应用程序,我希望能够在客户端对已发布的集合所做的所有更改写入服务器时进行检查。

我看过minimongoddp-server 中的代码,但我没有看到任何直接的方法来判断更改何时已成功写入服务器。

Minimongo 概述保存数据的过程:

  • 用户在客户端触发交互
  • 模拟对局部状态应用了一些突变
  • 触发 RPC 以在服务器上执行
  • 一段时间后,RPC 返回结果
  • 再过一段时间后,RPC 返回“已更新”消息(在 DDP 级别),这意味着来自 RPC 的所有更改都已保留
  • 此时我们知道,来自服务器的所有实际更改都已同步,我们可以丢弃模拟突变(保留来自服务器的真实更改)

我可以覆盖 LocalCollection.prototype.saveOriginalsLocalCollection.prototype.retrieveOriginals 来知道它们何时被调用,但我不确定如何验证何时数据实际上被保存了。 retrieveOriginals 即使在 Meteor 服务器关闭时也会被调用。

是否有任何其他地方可以 Hook 回调或监听事件以了解更改何时同步?

最佳答案

如果您希望实现自定义观察,也许这可能会有所帮助:

Establishes a live query that invokes callbacks when the result of the query changes. The callbacks receive the entire contents of the document that was affected, as well as its old contents, if applicable. If you only need to receive the fields that changed, see observeChanges.

http://docs.meteor.com/#/full/observehttp://docs.meteor.com/#/full/observe_changes

此外,您可能希望将 Mongo 的 writeConcern 与 Meteor 一起使用,我不确定如何使用,但希望提示有所帮助; https://docs.mongodb.org/v3.0/reference/method/db.collection.save/

关于javascript - 如何判断 Meteor minimongo 何时与 mongo 服务器同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33838294/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com