(I am an extreme newbie with extremely simple question):
If my database (from the documentation samples) consists of:
{ "item" : "journal", "qty" : 25, "size" : { "h" : 14, "w" : 21, "uom" : "cm" }, "status" : "A" }
{ "item" : "notebook", "qty" : 50, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "A" }
{ "item" : "paper", "qty" : 100, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "D" }
{ "item" : "planner", "qty" : 75, "size" : { "h" : 22.85, "w" : 30, "uom" : "cm" }, "status" : "D" }
{ "item" : "postcard", "qty" : 45, "size" : { "h" : 10, "w" : 15.25, "uom" : "cm" }, "status" : "A" }
I issue this command:
db.inventory.find( { item: /^j/ }, { size: 1 } )
I get back this document:
{
"_id" : ObjectId("59448e8544c2d6b6ced4ac66"),
"size" : {
"h" : 14.0,
"w" : 21.0,
"uom" : "cm"
}
}
What I want to do is, only get back "h". If I try this command:
db.inventory.find( { item: /^j/ }, { size.h: 1 } )
I get "Unexpected token ."
How can I cause only the "h" field of array "size" to return?
Thanks!
PS, I tried the example and answer in how to retrieve partial objects from object array in a field in mongodb, but the result was "Script executed successfully, but there are no results to show."
.Look at "Dot Notation" in the core documentation and the very clear example"<embedded document>.<field>"which very clearly shows the "quotes"""