Details
-
Task
-
Resolution: Duplicate
-
Major - P3
-
None
-
mongodb 2.6
-
0.25
Description
In the following URL, we explain how we may use projection on fields to limit the output structure of a document.
http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/
While one may use $slice to limit an array to a few of its elements, it is possible to select parts of that array, but also remove other fields as such
db.t.insert({_id:1, name:'mongouser', age:100, message:'try the new mongodb version 2.6', v:[1,2,3,4,5,6]})
Then try
db.t.find({},{name:1, age:1, message:0})
vs
db.t.find({},{name:0, age:0, v:{$slice:[-3,3]} })
Please modify You cannot combine inclusion and exclusion semantics in a single projection with the exception of the _id field.