[GIS] the best or recommended way to store a GeoJSON FeatureCollection in MongoDB

geojsonmongodb

The comments in this question: Shapefile to GeoJson conversion using C# raised another one: what is the best way to store a GeoJSON FeatureCollection in MongoDB? Is there any sort of convention when it comes to adding GeoJSON FeatureCollection to a MongoDB?

When I create a GeoJSON output with ogr2ogr:

ogr2ogr -f GeoJSON outshp.json c:\temp\us_counties_.shp

I get a json file and load that into MongoDB collection. The result is collection with a single document of type FeatureCollection, which contains all of the features:

enter image description here

It seems like a mongo collection and a featurecollection are redundant. Is there any sort of convention on how the Feature documents are stored? Are they typically left in their GeoJSON FeatureCollection? Or are they typically moved out of their GeoJSON FeatureCollection container once in a MongoDB?

enter image description here

Would there be any advantage in doing so?

The scope of my questions is the group of features that would be analogous to a shapefile or featureclass, not for cases were you start nesting geometries or feature json inside other documents.

Best Answer

It really depends on how you want to use the data once you have it in MongoDB. From the sounds of it, you will likely want to have a single MongoDB collection with a document for each feature.

This will allow you to use indexes and queries utilizing those indexes, most notably the 2dsphere index on the GeoJSON itself. There may be ways of doing that with a single document, but I don't think that makes much sense in this case.

Another thing to point out is that MongoDB is really only concerned with the geometry portion of the GeoJSON (for 2dsphere indexes). As you pointed out the FeatureCollection in the GeoJSON is mostly analogous to a collection in MongoDB. You could use the full hierarchy, but it's not required and may not make sense in some cases.

Related Question