【发布时间】:2018-01-28 08:27:06
【问题描述】:
我在我的国家/地区的 MongoDB 上有这个数据库,其中包含 OpenStreetMap 的数据,我使用 Node-Mongosm 导入它并生成三个集合:nodes、ways 和 relations。
请求 Way 时,输出以下文档(来自 mongo shell):
{
"_id":492464922,
"tags":{
"maxspeed":"20",
"surface":"asphalt",
"highway":"residential",
"oneway":"yes",
"name":"Avenida 1"
},
"loc":{
"type":"Polygon",
"coordinates":[
],
"nodes":[
445848963,
4844871065,
432568566
]
}
}
coordinates 字段为空,原因我不知道(不确定这是来自Node-Mongosm 的功能还是错误),但我可以从nodes 字段中检索每个节点的坐标来填充它,即:节点445848963:
{
"_id":445848963,
"loc":{
"type":"Point",
"coordinates":[
-83.5047254,
10.0984515
]
}
}
所以,我的问题是是否有可能以及我应该如何编写查询以从 ways 集合中收集文档,其中字段 coordinates 填充有节点(ways.loc.nodes field) 动态坐标,因此检索到的文档如下所示:
{
"_id":492464922,
"tags":{
"maxspeed":"20",
"surface":"asphalt",
"highway":"residential",
"oneway":"yes",
"name":"Avenida 1"
},
"loc":{
"type":"Polygon",
"coordinates":[
-83.5047254,
10.0984515,
-83.5052237,
10.0987132,
-83.5056339,
10.0989286
],
"nodes":[
445848963,
4844871065,
432568566
]
}
}
【问题讨论】:
标签: mongodb