是时候与 Meteor.Collection 共存了 [英] Time to live with Meteor.Collection

查看:41
本文介绍了是时候与 Meteor.Collection 共存了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Meteor Collection 是否提供任何使用 TTL(时间生活)来自mongodb的功能?需要这种用于具有临时数据的多用户会话.更改是否完全响应并不重要.

does a Meteor Collection provide any way to use the TTL (Time to live) feature from mongodb? Need this for a kind of multiuser-session with temporary data. It's not important that the changes are fully reactive.

推荐答案

这个答案的两个部分:

1) 要应用索引,您可以在 Meteor 中使用 _ensureIndex 方法,但是正如 _ 建议的那样,可以随时取消对此的支持.在可以传递的内容方面也可能存在限制,但对于像

1) to apply the index you can use the _ensureIndex method in Meteor, however as the _ suggests, support for this could be pulled anytime. There may also be limitation in terms of what can be passed, but for something as simple as

db.log.events.ensureIndex( { "status": 1 }, { expireAfterSeconds: 3600 } )

.. 然后是 mongo-livedata 的标准实现

.. then the standard implementation of mongo-livedata

self._collection._ensureIndex(index, options);

...应该足够了.

2) 我还没有测试过,但我很确定 TTL 会起作用.(另一方面,我测试了有上限的集合,它们确实有效).您看,DDP 在获取数据更改方面所做的工作有两个方面:

2) I haven't tested it, but I'm rather sure TTL will work. (I have on the other hand tested capped collections and they do work). You see, what DDP does in terms of picking up data changes is two fold:

  • 它在知道meteor 驱动的每次写操作后轮询mongo
  • 无论如何它每 10 秒轮询一次 mongo(用于带外更新)

第二部分意味着您可以手动进入 mongo shell,删除/添加/更新内容,更改将在不迟于 10 秒后反映.

Thats second part means that you can go in your mongo shell manually, delete/add/update stuff, and the changes will be reflected no later than 10 seconds afterwards.

在此基础上,如果您对 10 秒的反应延迟感到满意,那么 TTL 应该可以工作.

On that basis, if you're happy with the 10 second delay to reactivity, then TTL should work.

如果您对此不满意,可以尝试使用 Arunoda 的智能收藏,您可以在以下位置阅读更多信息:http://meteorhacks.com/introducing-smart-collections.html.他们从 oplog 中读取(如果你有的话),这样可能会减少反应性的延迟.请注意,这个概念虽然有趣,但也有 David Glasser 在这篇文章中提到的局限性:https://groups.google.com/d/msg/meteor-talk/h-ulU7guh1Y/nTfJ1F8uGxwJ

If you're not happy with this, you could try Arunoda's smart collections, which you can read more about on: http://meteorhacks.com/introducing-smart-collections.html. They read from the oplog (if you have one), so that might reduce the delay to reactivity. Note that this concept, while interesting, has limitations that David Glasser has covered in this post: https://groups.google.com/d/msg/meteor-talk/h-ulU7guh1Y/nTfJ1F8uGxwJ

无论如何,祝你好运,让我们知道你的进展.

In any case, good luck and let us know how you get on.

这篇关于是时候与 Meteor.Collection 共存了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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