0

Trying to import Google Maps geojson data into a MongoDB and thought it would be quite easy to do so, since the geojson data is quite similar to json. Turns out to be uncomfortably difficult.

My Google Maps geojson data looks like this:

{
"type": "FeatureCollection",
"name": "All",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "Name": "KSA", "description": "750 acres" }, "geometry": { "type": "Point", "coordinates": [ -72.8032981, 43.6176027 ] } },
{ "type": "Feature", "properties": { "Name": "JPR", "description": null }, "geometry": { "type": "Point", "coordinates": [ -72.5045437, 44.9379601 ] } },
:
{ "type": "Feature", "properties": { "Name": "SAM", "description": null }, "geometry": { "type": "Point", "coordinates": [ 10.1589005, 47.1394002 ] } }
]
}

The responses that seemed most applicable were these threads: How to import Geojson file to MongoDB and Unexpected end of JSON input in MongoDB Compass

But after pruning the document, and removing the commas between the documents, I either had MongoDB refusing to import, citing various errors such as "Unexpected end of JSON input", or similar failures from various online minifiers & validators.

While ok with a command line, I'm not comfortable with how the MongoDB command line works (having only used Compass), so the potential command line solutions seem unclear to me as to how they work.

I'd have thought it would be simple to push the cleaned up json through an online minification tool, yet so far its not working.

To save further hours, does anyone have a suggestion as to how to get an online tool and this import to work please?

christo
  • 127
  • 1
  • 2
  • 12

1 Answers1

0

Ah all good, I eventually got it to work.

As per answer from Adam on another thread, I removed this from the beginning:

{
"type": "FeatureCollection",
"name": "US Features",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [

and this from the end:

]
}

I then removed the commas at the end of each line, ie. I replaced "] } }," with "] } }"

Then ran it through jq play with "compact output" selected.

Then saved it to a file and MongoDB then happily imported it.

Still not sure why I was unable to get it to work with the other minifiers, but jq play certainly did the trick.

christo
  • 127
  • 1
  • 2
  • 12