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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -