gpt4 book ai didi

mongodb - 在索引字段与可尾光标上轮询 MongoDb

转载 作者:IT老高 更新时间:2023-10-28 13:22:51 26 4
gpt4 key购买 nike

在 MongoDb 关于可尾游标的文档中,它声明如下:

If your query is on an indexed field, do not use tailable cursors, but instead, use a regular cursor. Keep track of the last value of the indexed field returned by the query. To retrieve the newly added documents, query the collection again using the last value of the indexed field in the query criteria

我正在设置一个查询来查找特定时间点之后的所有文档,然后在插入文档时继续返回它们。我想最简单的方法是在 _id (假设我们使用 ObjectIds,我们就是)上查询任何我想要的时间 $gt。

由于 _id 默认被索引,用我得到的最后一个 _id 不断轮询 MongoDb 并不断询问 $gt 它有多糟糕?我意识到这只会在 1 秒内精度左右,因为 ObjectIds 只存储自纪元以来的秒数,但我可以忍受,所以我假设我每秒至少查询一次。

我想我只是惊讶于文档推荐的查询方法(在我的情况下可能是持续的)而不是保持可尾光标打开:我会认为推送会比拉更便宜?

最佳答案

这里有一个重要的警告,我认为您可能已经忽略了。可拖尾光标适用于 capped collections .使用上限集合可能不是通用解决方案,它需要仔细规划以确保您适当调整上限集合的大小以适应您的数据大小和增长。

关于mongodb - 在索引字段与可尾光标上轮询 MongoDb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42642241/

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