Importing OSM Data into MongoDB?

Importing OSM Data into MongoDB?

Can anyone tell me how to import OSM data in mongoDB step by step ?

This is the link to the data

this is the error i am getting in the 1 step:

Unable to open datasource with the following drivers… [huge list]

So this is how I do it:
1.) convert the osm.pbf file to geojson with ogr2ogr like this:

ogr2ogr -f GeoJSON points.json C:dataosmkarlsruhe-regbez-latest.osm.pbf points

the only trick is that you have to enter this statement five times, changing the type of the geometry at the end of the statement :

points / lines / multilinestrings / multipolygons / other_relations

now you have five .json files

2.) Edit each file by deleting these parts:

  • the first two lines of the file:
{"type": "FeatureCollection", "features": [
  • the last two lines of the file:
] }
  • and the comma at the end of each row
    this step I do with the search&replace feature of notepad++, like this:

(the number of the brackets may vary for different geometry types)

so now you have five json files which can be imported to mongodb

3.) import the json data to mongodb
in the commander cd to mongodb/bin and type:

> mongoimport --db dbname --collection points --file C:datapath	opoints.json

Here you can also put all 5 files in one collection.

I know this sounds a lot of work at first, but I did not find any other way which would be quicker.
I hope this helps :)

I found a software with which you can do it in one step: osm2mongo
Please note that for this you need to download the osm.bz2 format, not the osm.pbf one. After download you should extract it, so you have a karlsruhe-regbez-latest.osm file.
Then in the commander cd to the osm2mongo.exe and type

>osm2mongo -i karlsruhe-regbez-latest.osm -h localhost:27017 -d dbname

The drawback is, that it has a bit different data structure. It creates 3 collections: nodes, relations and ways.
But it is definitely easier to import with this software in just one step.

This can be done using the mongosm importer.

  1. Download the osm file:
  2. Extract the file. Try f.ex. 7zip, orbunzip2 karlsruhe-regbez-latest.osm.bz2in a shell.
  3. Download the repo :git clone --depth 1
  4. python mongosm/ karlsruhe-regbez-latest.osmimports the data.

Only thing that I know is Osmo but IMHO the best/best supported method is using PostgreSQL as it's most supported solution by the OSM tools.


Kansas ( / ˈ k æ n z ə s / ( listen ) ) is a state in the Midwestern United States. [10] Its capital is Topeka and its largest city is Wichita. [11] Kansas is bordered by Nebraska to the north Missouri to the east Oklahoma to the south and Colorado to the west. Kansas is named after the Kansas River, which in turn was named after the Kansa Native Americans who lived along its banks. [12] [13] [14] [15] The tribe's name (natively kką:ze) is often said to mean "people of the (south) wind" although this was probably not the term's original meaning. [16] [17] For thousands of years, what is now Kansas was home to numerous and diverse Native American tribes. Tribes in the eastern part of the state generally lived in villages along the river valleys. Tribes in the western part of the state were semi-nomadic and hunted large herds of bison.

Kansas was first settled by Americans in 1827 with the establishment of Fort Leavenworth. The pace of settlement accelerated in the 1850s, in the midst of political wars over the slavery debate. When it was officially opened to settlement by the U.S. government in 1854 with the Kansas–Nebraska Act, abolitionist Free-Staters from New England and pro-slavery settlers from neighboring Missouri rushed to the territory to determine whether Kansas would become a free state or a slave state. Thus, the area was a hotbed of violence and chaos in its early days as these forces collided, and was known as Bleeding Kansas. The abolitionists prevailed, and on January 29, 1861, [18] [19] Kansas entered the Union as a free state, hence the unofficial nickname "The Free State".

By 2015, Kansas was one of the most productive agricultural states, producing high yields of wheat, corn, sorghum, and soybeans. [20] Kansas, which has an area of 82,278 square miles (213,100 square kilometers) is the 15th-largest state by area and is the 34th most-populous of the 50 states with a population of 2,940,865 [21] according to the 2020 census. Residents of Kansas are called Kansans. Mount Sunflower is Kansas's highest point at 4,039 feet (1,231 meters). [22]