如何将GeoJSON功能存储到集合中的单个文档中,而不是Mongo中具有嵌套功能的一个文档

时间:2018-03-06 13:33:47

标签: json mongodb mongodb-query geojson mongo-shell

我有一个这种形式的GeoJson文件(示例如下所示):

{
   "type": "FeatureCollection",
   "features": [{
       "type": "Feature",
       "geometry": {
           "type": "Point",
           "coordinates": [102.0, 0.5]
       },
       "properties": {
           "prop0": "value0"
       }
   }, {
       "type": "Feature",
       "geometry": {
           "type": "LineString",
           "coordinates": [
               [102.0, 0.0],
               [103.0, 1.0],
               [104.0, 0.0],
               [105.0, 1.0]
           ]
       },
       "properties": {
           "prop0": "value0",
           "prop1": 0.0
       }
   }, {
       "type": "Feature",
       "geometry": {
           "type": "Polygon",
           "coordinates": [
               [
                   [100.0, 0.0],
                   [101.0, 0.0],
                   [101.0, 1.0],
                   [100.0, 1.0],
                   [100.0, 0.0]
               ]
           ]
       },
       "properties": {
           "prop0": "value0",
           "prop1": {
               "this": "that"
           }
       }
   }]
 }

当我在一个名为sampledb的表中将此文件导入mongo时 并在一个名为samplecol的集合中使用此命令mongoimport --db sampledb --collection samplecol --drop --file /home/ec2-user/sample.json我在mongo shell中执行:

db.samplecol.findOne()

此命令返回所有功能。我想知道如何将GeoJSON功能存储到集合中的单个文档中而不是一个具有嵌套功能的文档。

提前致谢。

0 个答案:

没有答案