2016-02-18 65 views
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。

在这方面的任何帮助将不胜感激。提前致谢。

回答

1

您可以添加额外的查询{...}像这里面:

db.storelist.find({ 
    "storeName": "The Home Depot", 
    location: { 
    $nearSphere: { 
     $geometry: { 
     type: "Point", 
     coordinates: [-121.8683031, 37.3029936] 
     }, 
     $maxDistance: 2000 
    } 
    } 
}) 
+0

非常感谢。这完全按照我想要的方式工作。 –

相关问题