Query array element and then field, from MongoDB -
suppose have following document in collection:
{ "_id":objectid("1123562e7c594c12942f"), "figures":[ { "shape":"square", "color":"blue" }, { "shape":"triangle", "color":"black" } ] } i make query selects field "shape" second element of array "figures".
using db.test.find({}, {"figures": {$slice: [2, 1]}}) can access second element of "figures", can select only field "shape" there?
use below query
db.test.find({}, {"figures": {$slice: [2, 1]}, "figures.shape": 1}).pretty();
Comments
Post a Comment