问题描述
我想对文档的嵌套数组中的分页应用跳过和限制,如何执行此[有效方式]
I want to apply skip and limit for paging in nested array of a document how can I perform this [Efficient Way]
我的文档的重印为
{
"_id":"",
"name":"",
"ObjectArray":[{
"url":"",
"value":""
}]
}
我想检索多个文档,每个文档都包含'n'个记录.
I want to retrieve multiple document and every document contain 'n' number of record.
我在查找查询中使用$in
来检索基于_id的多条记录,但是如何在每个文档中获取一定数量的ObjectArray
元素?
I am using $in
in find query to retrieve multiple record on basis of _id but how can i get certain number of element of ObjectArray
in every document?
推荐答案
您可以尝试这样-
db.collection.find({}, {ObjectArray:{$slice:[0, 3]}})
这将为您提供0..3
$slice:[SKIP_VALUE, LIMIT_VALUE]}
您的示例:-
db.collection.find({"_id":""}, {ObjectArray:{$slice:[0, 3]}})
此处是MongoDB Slice功能的参考. http://docs.mongodb.org/manual/reference/operator/projection/slice/
Here is the reference for MongoDB Slice feature.http://docs.mongodb.org/manual/reference/operator/projection/slice/
这篇关于跳过并限制嵌套数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!