我正在寻找找到特定中餐馆的城市。我有2个收藏集:餐厅和邮政编码。
我首先创建了所有中餐馆的变量。
var chinese = db.restaurants.find({"name" : /chinese/i});
现在,我希望使用坐标来找出餐厅在哪里。
一家餐厅的示例:
{"_id":"55cba2476c522cafdb053c83","location":{"coordinates":[-92.73084399999999,41.7461462],"type":"Point"},"name":"Charlie'S Mom Chinese Restaurant"}
邮政编码收集示例:
{"_id":"01001","city":"AGAWAM","loc":[-72.622739,42.070206],"pop":15338,"state":"MA"}
我尝试过这样创建索引:
db.zipcodes.createIndex({"loc" : "2dsphere"});
db.restaurants.createIndex({"loc" : "2dsphere"});
并尝试在geowithin内
db.zipcodes.find({loc : {$geoWithin: { $geometry: chinese.geometry } } });
但是,我觉得我做错了
谢谢您的帮助!