Export data from MongoDB 3.0 and import it into MongoDB 2.6

I just had the dream meeting with a dockerized app. This is a use-case for containerization.

I had to use MongoDB 3.0 to export some data and place it in a 2.6. Ouch: The 2.6 can’t connect to the 3.0.

A genius sat down at the exact moment of my complaining. “Just use Docker.”

So – to get and run the 3.0 Docker image of MongoDB – started with a bash shell:

docker run -ti --rm -v /Users/olle/slask/portal-test:/backup mongo:3.0 /bin/bash

(Related: this works because of the last line in its ENTRYPOINT script: entrypoint.sh (see 3.0/docker-entrypoint.sh))

When that pulls down and starts the shell, things are automated, and we land in a shell.

There, we can do the 3.0 invocation of mongodump:

mongodump -h ds012345-a0.mongolab.com:12345 -d portal-test -u portal-user -p secret -o /backup/portal-test

This gave me a dump folder at:

/Users/olle/slask/portal-test/portal-test/portal-test

I had been too generous with the wrapping folders. No biggie.

Then, the local 2.6 invocation:

mongorestore -d portal-test /Users/olle/slask/portal-test/portal-test/portal-test

Bam.

Leave a Reply

Your email address will not be published. Required fields are marked *