跳过和限制嵌套数组元素
Skip and Limit on nested array element
我想对文档的嵌套数组中的分页应用跳过和限制如何执行此[有效方式]
我的文档记录得像
{
"_id":"",
"name":"",
"ObjectArray":[{
"url":"",
"value":""
}]
}
我想检索多个文档,每个文档包含 'n' 条记录。
我在查找查询中使用 $in
来根据 _id 检索多条记录,但我如何才能在每个文档中获得一定数量的 ObjectArray
元素?
你可以这样试试-
db.collection.find({}, {ObjectArray:{$slice:[0, 3]}})
这将为您提供来自 0..3
的记录
$slice:[SKIP_VALUE, LIMIT_VALUE]}
举个例子:-
db.collection.find({"_id":""}, {ObjectArray:{$slice:[0, 3]}})
这里是 MongoDB 切片功能的参考。
http://docs.mongodb.org/manual/reference/operator/projection/slice/
我想对文档的嵌套数组中的分页应用跳过和限制如何执行此[有效方式]
我的文档记录得像
{
"_id":"",
"name":"",
"ObjectArray":[{
"url":"",
"value":""
}]
}
我想检索多个文档,每个文档包含 'n' 条记录。
我在查找查询中使用 $in
来根据 _id 检索多条记录,但我如何才能在每个文档中获得一定数量的 ObjectArray
元素?
你可以这样试试-
db.collection.find({}, {ObjectArray:{$slice:[0, 3]}})
这将为您提供来自 0..3
$slice:[SKIP_VALUE, LIMIT_VALUE]}
举个例子:-
db.collection.find({"_id":""}, {ObjectArray:{$slice:[0, 3]}})
这里是 MongoDB 切片功能的参考。 http://docs.mongodb.org/manual/reference/operator/projection/slice/