So this is how I do it:
1.) convert the osm.pbf file to geojson with ogr2ogr
ogr2ogr -f GeoJSON points.json C:\data\osm\karlsruhe-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:
- 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:\data\path\to\points.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.