0
{
 "_id":123456,
 "Menu":[{
    "Dish":"Apple pie",
    "Rating": "Good",
    "Method": "Oven Baked"
   },

   {
     "Dish":"Pumpkin Pie",
    "Rating": "Bad",
    "Method": "Baked"
   },
   {
    "Dish":"Tomato Soup",
    "Rating": "Good",
    "Method": "Boiled"
   }]

}

How do I query this array if I would only like to display the values in the field "Method"?

How do I solve this with Pymongo?

errata
  • 5,695
  • 10
  • 54
  • 99
  • 1
    You can use the `projection` in your query: http://api.mongodb.com/python/current/api/pymongo/collection.html?highlight=projection#pymongo.collection.Collection.find – errata May 30 '17 at 13:56

1 Answers1

0

Use the below Mongo Shell query

 db.mycollection.find({_id:123456}, {"Menu.Method":1})

This query will yield the below result on your sample document

{
        "_id" : 123456,
        "Menu" : [
                {
                        "Method" : "Oven Baked"
                },
                {
                        "Method" : "Baked"
                },
                {
                        "Method" : "Boiled"
                }
        ]
}
Clement Amarnath
  • 5,301
  • 1
  • 21
  • 34