Reputation: 279
Mongo document structure as follows:
{
"dictID" : "dd001",
"dictVersion" : 1,
"addMeasures" :
[
{
"measureId" : "f229ba18",
"userId" : "3966C3DD",
"created" : "2017-01-07T05:47:22.512Z"
}, {
"measureId" : "0b701469",
"userId" : "3966C3DD",
"created" : "2017-01-07T05:47:35.193Z"
} , {
"measureId" : "f229ba1823",
"userId" : "3966C3DD",
"created" : "2017-01-07T05:47:22.512Z"
}, {
"measureId" : "0b7014699",
"userId" : "3966C3DD",
"created" : "2017-01-07T05:47:35.193Z"
}
]
}
I need a pagination for single document on array list
Ex. In my document "addMeasures" has multiple maps, I want pagination on it so that it should give me part "addMeasures" like limit 1,2.
Upvotes: 1
Views: 87
Reputation: 9295
use the $slice operator
db.collection.find({}, {dictId: 1, dictVersion: 1, addMeasures: {$slice: [0, 2]}})
returns:
{
"_id":ObjectId("5890572371cbc5eae2c9535b"),
"dictVersion":1,
"addMeasures":[
{
"measureId":"f229ba18",
"userId":"3966C3DD",
"created":"2017-01-07T05:47:22.512Z"
},
{
"measureId":"0b701469",
"userId":"3966C3DD",
"created":"2017-01-07T05:47:35.193Z"
}
]
}
Upvotes: 1