在mongo shell中,我已将以下文档插入到guest集合中:
{
"name": "Jackson",
"title": "Sir",
"preferences": [
{
"Restaurant": "LobsterHouse"
},
{
"Room": "333"
},
{
"Transportation": [
"Limo",
"Town Car",
"Taxi"
]
}
]
},
{
"name": "Peterson",
"title": "Mr",
"preferences": [
{"Restaurant": "Lobster House"},
{"Room": "321"},
{"Transportation": "Town Car"}
]
},
{
"name": "Hodgson",
"title": "Mrs",
"preferences": [
{"Restaurant": "The Sushi Bar"},
{"Room": "180"},
{"Transportation": "Taxi"}
]
}
我希望能够以这两种方式进行搜索,
1)获取内部偏好的所有客人,运输等于“出租车”
我试过了:
db.guests.preferences.find({"Transportation":"Taxi"})
我也试过以下的查找方法,只回到“Hodgson”
db.guests.find({preferences: {"Transportation":"Taxi"}})
我无法理解为什么它不会进入“杰克逊”并找到“运输”项目数组中的值
非常感谢任何帮助