1
我有一個具有座標的位置字段的mongodb集合。在進行過濾器搜索時,我希望獲取範圍內的文檔和特定名稱,我的例子是storeName。在這方面有什麼幫助? 以下是我的收藏。查詢具有地理空間索引和字段的Mongodb集合
{
"uuid" : "1cf92c0a-5fd6-11e5-b541-9fed3d5db33a",
"type" : "store",
"created" : 1442780891840,
"modified" : 1442780891840,
"address" : {
"address" : "1285 Lincoln Ave",
"city" : "San Jose",
"state" : "CA",
"zip" : "95125",
"country" : "US"
},
"hours" : "Mon-Sat 7:00 am- 10:00 pm, Sun 8:00 am- 9:00 pm",
"location":{"coordinates":[-121.8990201,37.3049792],"type":"Point"},
"nid" : "18",
"phoneNumber" : "(408) 280-5124",
"storeName" : "CVS Pharmacy - Photo",
"storeTag" : "pharmacy",
"website" : "http://www.cvs.com/store-locator/cvs-pharmacy-address/1285+Lincoln+Avenue-San%20Jose-CA-95125/storeid=9559?WT.mc_id=LS_GOOGLE_9559"
}
{
"uuid" : "1bd7414a-5fd6-11e5-bfb7-6d8e86e17b6b",
"type" : "store",
"created" : 1442780889940,
"modified" : 1442780889940,
"address" : {
"address" : "1130 BIRD AVE",
"city" : "San Jose",
"state" : "CA",
"zip" : "95125",
"country" : "US"
},
"hours" : "Mon-Sun 7:00 am- 12:00 am",
"location":{"coordinates":[-121.8943393,37.3108209],"type":"Point"},
"nid" : "14",
"phoneNumber" : "(408)-295-7768",
"storeName" : "Walgreens",
"storeTag" : "pharmacy",
"website" : "http://www.walgreens.com/locator/walgreens-1130+bird+ave-san+jose-ca-95125/id=2265"
}
{
"uuid" : "1c22c93a-5fd6-11e5-b9e3-35f3c41288ef",
"type" : "store",
"created" : 1442780890435,
"modified" : 1442780890435,
"address" : {
"address" : "2181 Monterey Hwy",
"city" : "San Jose",
"state" : "CA",
"zip" : "95125",
"country" : "US"
},
"hours" : "Mon-Sat 6:00 am- 10:00 pm, Sun 7:00 am- 8:00 pm",
"location":{"coordinates":[-121.8683031,37.3029936],"type":"Point"},
"nid" : "15",
"phoneNumber" : "(408) 971-4890",
"storeName" : "The Home Depot",
"storeTag" : "hardware",
"website" : "http://www.homedepot.com/l/San-Jose-ge/CA/San-Jose/95125/1861"
}
這是目前爲止的查詢。
db.storelist.find({ location: { $nearSphere: { $geometry: { type: "Point", coordinates: [ -121.8683031,37.3029936 ] }, $maxDistance: 2000 } } })
我得到距離內的文件列表,但無法理清我放置其他字段的位置,即storeName。
在這方面的任何幫助將不勝感激。提前致謝。
非常感謝。這完全按照我想要的方式工作。 –