【发布时间】:2019-10-11 18:38:22
【问题描述】:
我们能否进行查询,使我们能够在前 N 个文档中使用跳过和限制?
例如:
假设在一个名为教师的集合中有近 500 个文档。
我想要一个限制我只能阅读前 300 个文档的查询。
如果我在该查询中使用 skip(300),它应该显示 null。
db.teachers.find().pretty()
{
id : 1,
name : "teach001"
},
{
id : 2,
name : "teach002"
},
{
id : 3,
name : "teach003"
},
{
id : 4,
name : "teach004"
},
{
id : 5,
name : "teach005"
},
{
id : 6,
name : "teach006"
},
{
id : 7,
name : "teach007"
},
{
id : 8,
name : "teach008"
},
{
id : 9,
name : "teach009"
},
{
id : 10,
name : "teach0010"
}
db.teachers.find({some query here to restrict access first 5 documents only }).skip(5).limit(5).pretty()
【问题讨论】:
-
请通过一些示例数据和查询为您的问题添加更多详细信息。
-
我认为您需要在代码中预处理查询的跳过和限制参数以强制执行您想要的任何规则。
标签: mongodb mongodb-query