This was raised earlier in 2010 and wondering whether this restriction is still there? I'd like to avoid doing this by mapreduce.
Appreciate quick reply from gurus
http://stackoverflow.com/questions/3985214/mongodb-extract-only-the-selected-item-in-array
Suppose you have the following:
// Document 1 { "shapes" : [ {"shape" : "square", "color" : "blue"}, {"shape" : "circle","color" : "red"} ] } // Document 2 { "shapes" : [ {"shape" : "square", "color" : "black"}, {"shape" : "circle", "color" : "green"} ] }
do query:
db.test.find({"shapes.color":"red"}, {"shapes.color":1})
or
db.test.find({shapes: {"$elemMatch": {color: "red"}}}, {"shapes.color":1})
return document (Document 1) matched, but with always ALL array items in shapes:
{ "shapes" : [ {"shape" : "square", "color" : "blue"}, {"shape" : "circle","color" : "red"} ] }
I just want document (Document 1) filtered with ONLY array item color=red:
--{ "shapes" : [ {"shape" : "circle","color" : "red"} ] }
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
can someone clarify returning first matching row only is intended functionality or bug?Based on doc, it appears to be bug.Appreciate if some one can clarify