Suppose I have the following document in a collection:
{
"_id":ObjectId("1123562e7c594c12942f"),
"figures":[
{
"shape":"square",
"color":"blue"
},
{
"shape":"triangle",
"color":"black"
}
]
}
I would like to make a query which selects the field "shape" from the second element of the array "figures".
Using db.test.find({}, {"figures": {$slice: [2, 1]}}) you can access the second element of "figures", but can you also select only the field "shape" from there?
.find()? No. You can use the.aggregate()method. But it's better to do this client side.