gpt4 book ai didi

mongodb - 是提示({$自然: 1}) redundant when using a tailable cursor?

转载 作者:可可西里 更新时间:2023-11-01 10:43:28 25 4
gpt4 key购买 nike

在我发现的许多在上限集合上使用可尾游标的示例中,代码包括:

hint( { $natural: 1 } )

(例如 here ),包括官方文档 ( here ),以“确保我们不使用任何索引”,并且结果以自然(即磁盘)顺序返回。

但是,文档还表明这是可尾游标的默认行为:

Tailable cursors do not use indexes and return documents in natural order.

那么提示的使用是多余的吗?

我试着查看 explain() 的输出,有和没有 hint,据我所知,没有区别。

最佳答案

是的,是的。

有时你可能想做的是以相反的自然顺序返回结果(最后插入的文档最先返回。你可以通过以下方式实现:

db.cappedCollection.find().sort({$natural:-1})

有效地将上限集合的 FIFO 性质更改为 LIFO 性质。

关于mongodb - 是提示({$自然: 1}) redundant when using a tailable cursor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26573454/

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