gpt4 book ai didi

mongodb - 在 mongodb 中,如何获取 10 个 id 小于 100 但不是从 1 到 10 而不是从 90 到 99 的文档

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

我有一个 mongodb 集合,其 id 字段上的索引按升序排列。

如何从集合中获取 10 个文档,其 id 小于 100 但不是前 10 个而是后十个小于 100。

下面的查询给出了从 1 到 10 的数据。

db.products.find({id:{$lt:100}}).limit(10)

最佳答案

db.products.find({id:{$lt:100}}).sort({"id":-1}).limit(10)

关于mongodb - 在 mongodb 中,如何获取 10 个 id 小于 100 但不是从 1 到 10 而不是从 90 到 99 的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33499125/

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