The following query in mongo behaves strangely:
db.items.findOne({},{ "List": { "$slice": [ skip, 3 ] }})
First: Instead of returning a single object with just ["_id", "List"], it returns the full object.
Secondly: if skipnegative, but |skip|higher than list.length, then it returns the first three elements, as ifskip==0
I would expect:
{
"_id" : ObjectId("542babf265f5de9a0d5c2928"),
"List" : [
1,
2,
3,
4,
5
]
"other" : "not_important"
}
inquiry:
db.items.findOne({},{ "List": { "$slice": [-10, 3 ] }})
To obtain:
{
"_id" : ObjectId("542babf265f5de9a0d5c2928"),
"List" : []
}
instead, I get:
{
"_id" : ObjectId("542babf265f5de9a0d5c2928"),
"List" : [
1,
2,
3
]
"other" : "not_important"
}
Why?
I am using mongoDB 2.4.10
source
share