Mongodb projection returning a given position -
i trying simple return subarray of document. query is:
db.mydocs.findone({_id:objectid("af7a85f758e338d762000012")},{'house.0.room.4.windows':1});
i want return value. empty structure. know $slice. far know, can't subarrays. mean: {'house':{'$slice':0}}
work. don't know how house 0 , room 4.
you'll have use chained $slice
operators work:
db.mydocs.findone( {_id:objectid("af7a85f758e338d762000012")}, {"house" : {$slice : [0,1]}, // house.0 "house.room" :{$slice : [3,1]}, // house.0.room.4 "house.room.windows" : 1}); // house.0.room.4.windows
the resulting document this, i.e. arrays still arrays (which helpful when mapping typed languages):
house : [ { room : [ { windows : foo } ] } ]
from the documentation:
tip: mongodb not support projections of portions of arrays except when using
$elemmatch
,$slice
projection operators.
p.s: find irritating house
, room
arrays, have singular names, esp. because windows
is plural.
Comments
Post a Comment