【发布时间】:2015-11-15 17:35:38
【问题描述】:
我有一个名为“cupcakes”的集合,它是使用 mongoimport 从 GeoJSON 文件加载的。 GeoJSON 可以在here 找到,它是一个已知的有效 JSON 文件。这部分似乎已经计划好了,并且正在做:
use cupcakes
db.cupcakes.find({ })
这会按预期撤回所有功能。但是,我正在尝试执行一个查询,该查询将仅返回将无麸质设置为“no”的功能。
我已按照有关查询 arrays of documents 的文档尝试了说明。
db.cupcakes.find({features: { $elemMatch: { "properties.gluten free":"no"}}}).pretty()
但据我所知,这似乎是返回所有的功能,而不是只是那些不含麸质的场所。
本质上,我想撤回所有“properties.gluten free”功能设置为“no”(或“yes”)的功能。
示例输出可能是:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-122.70069837570189,
45.53570881624427
]
},
"properties": {
"name": "Le Cookie Monkey",
"address": "1902 NW 24th Avenue",
"website": "http://www.lecookiemonkey.com/",
"gluten free": "no",
"open1": "Tuesday - Friday, 9am - 3pm",
"open2": "Saturday, 9am - 2pm"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-122.6375323534012,
45.5219957171348
]
},
"properties": {
"name": "Crema Coffee + Bakery",
"address": "2728 SE Ankeny Street",
"website": "http://www.cremabakery.com/",
"gluten free": "no",
"open1": "Monday - Sunday, 7am - 6pm"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-122.60960519313811,
45.472775425296014
]
},
"properties": {
"name": "Mehri's Bakery & Deli",
"address": "6923 SE 52nd Avenue",
"website": "http://www.mehris.com/",
"gluten free": "no",
"open1": "Monday - Friday, 7am - 7pm",
"open2": "Saturday, 8am - 5pm",
"open3": "Sunday, 8am - 2pm"
}
},
... 以此类推,直到返回 "gluten free" : "no" 的所有特征。
我在这里缺少什么?提前致谢。
【问题讨论】:
标签: json mongodb mongodb-query geojson