我有一个mongodb集合,它有一个带坐标的位置字段。在进行过滤搜索时,我想在一个范围和特定名称中获取文档,在我的情况下是storeName。在这方面有什么帮助吗? 以下是我的收藏。
{
"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。
在这方面的任何帮助将受到高度赞赏。提前谢谢。
答案 0 :(得分:1)
您可以在{...}
内添加其他查询,如下所示:
db.storelist.find({
"storeName": "The Home Depot",
location: {
$nearSphere: {
$geometry: {
type: "Point",
coordinates: [-121.8683031, 37.3029936]
},
$maxDistance: 2000
}
}
})