问题:编写MongoDB查询以查找位于纬度值小于-95.754168的餐馆。
'餐馆'集合的结构
{
"address": {
"building": "1007",
"coord": [ -73.856077, 40.848447 ],
"street": "Morris Park Ave",
"zipcode": "10462"
},
"borough": "Bronx",
"cuisine": "Bakery",
"grades": [
{ "date": { "$date": 1393804800000 }, "grade": "A", "score": 2 },
{ "date": { "$date": 1378857600000 }, "grade": "A", "score": 6 },
{ "date": { "$date": 1358985600000 }, "grade": "A", "score": 10 },
{ "date": { "$date": 1322006400000 }, "grade": "A", "score": 9 },
{ "date": { "$date": 1299715200000 }, "grade": "B", "score": 14 }
],
"name": "Morris Park Bake Shop",
"restaurant_id": "30075445"
}
作者的答案是:db.restaurants.find({“address.coord”:{$ lt:-95.754168}});
这是正确的答案吗? 如果没有,那么正确答案是什么?
资源:http://www.w3resource.com/mongodb-exercises/#PracticeOnline
答案 0 :(得分:1)
您可以像这样进入coord
索引
db.restaurants.find({"address.coord.0" : {$lt: -95.754168}});
根据文件here,
MongoDB使用点表示法来访问数组的元素并访问嵌入文档的字段。
E.g。
<array>.<index>
请注意,索引是从0开始的。