How to “compile” ways and relations from OSM Planet

I need to get political boundaries, house polygons and some other data from OSM. To do that I downloaded OSM Planet dump, converted it into .pbf format (cause its fast and doesn’t take a lot of space). Then, created a streamer that imported nodes, ways and relations into my database (MongoDB).

Now I need to “compile” ways from nodes (in each way instead of reference to nodes, put their coordinates) and then compile relations from them both.

I tried to do that using Redis (key-value in-memory database) as compact as I could (id as key + lat,lon as value). But couldn’t even import nodes - it stopped on 14% (I have 128 GB RAM)

My next try was to do the same thing with MongoDB but it’s too slow.

How can I achieve this? Are there any tools like osmconvert or osmfilter that will will take ways and nodes, and output ways containing actual coordinates?

Thanks in advance for any help

You probably should use osmfilter to reduce the data.
shows a command to filter administrative boundaries and postal_code areas.
Something similar is needed for buildings polygons/multipolygons.
I suggest to try this first with a small extract of maybe 20MB so that you can use JOSM to verify the results.
Edit: typos