Python 如何在mongodb中查询数组
} 如果我只想显示字段“Method”中的值,如何查询此数组Python 如何在mongodb中查询数组,python,mongodb,Python,Mongodb,} 如果我只想显示字段“Method”中的值,如何查询此数组 如何使用Pymongo解决这个问题?使用下面的Mongo Shell查询 { "_id":123456, "Menu":[{ "Dish":"Apple pie", "Rating": "Good", "Method": "Oven Baked" }, { "Dish":"Pumpkin Pie", "Rating": "Bad", "Method": "Baked"
如何使用Pymongo解决这个问题?使用下面的Mongo Shell查询
{
"_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"
}]
此查询将在示例文档上生成以下结果
db.mycollection.find({_id:123456}, {"Menu.Method":1})
您可以在查询中使用
投影
:
{
"_id" : 123456,
"Menu" : [
{
"Method" : "Oven Baked"
},
{
"Method" : "Baked"
},
{
"Method" : "Boiled"
}
]
}