Restoring a database dump of an old version of mongo to a new version of mongo

I currently have an old version of mongo, i.e. 2.6 is working on my system. I already have my site in production and you have a lot of customer data. I am planning to upgrade to mongo 3.2.

So my question is: does mongorestore mongo v3.2 work with data dump v2.6 ? Or is it known that it creates problems?

Any answers would be invaluable! thanks

+5
source share
2 answers

Since you have data from mongo 2.6, the index field restriction has already been implemented. Mongo 3.2 will restore this backup without any problems.

Another way you can update your db (if you have a set of replicas) is to replace one member of 2.6 with 3.2 and wait for synchronization, then another ... This will give you business continuity :-)

+5
source

I asked this same question on the official MongoDB mailing list . They stated that they would not update more than one major version at a time. (Major versions: 2.2, 2.4, 2.6, 3.0, 3.2, 3.4)

I did not want to follow the normal process of updating each version. Just to start mongod, then unplug it. It seems to me that it would remain cool, and I like my infrastructure building to be written and versioned. So, I decided to launch new EC2 instances with the latest Ubuntu (since my Mongo v2.4 servers were also 2 LTS versions) and the latest MongoDB. I used image dockers of intermediate versions of MongoDB to update data.

https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f#file-uat_mongodb_upgrade_from_prod-sh

The main part of the solution is as follows:

# mongo.conf is using the default dbPath: /var/lib/mongodb # this path is for temporary use by the mongo docker container mkdir -p /data/db/dump # see: https://hub.docker.com/_/mongo/ (search for /data/db) # see: https://github.com/docker-library/mongo/blob/30d09dbd6343d3cbd1bbea2d6afde49f5d9a9295/3.4/Dockerfile#L59 cd /data/db mongodump -h prodmongo.int # Get major versions from https://hub.docker.com/r/library/mongo/tags/ step=0 for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do sudo docker stop some-mongo || true sudo docker rm some-mongo || true sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:$major_version false; while [[ $? > 0 ]]; do sleep 0.5 sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())' done if (( $step == 0 )); then sudo docker exec -it some-mongo mongorestore /data/db/dump fi ((step += 1)) done # Finish up with docker sudo rm -rf /data/db/dump/* sudo docker exec -it some-mongo bash -c 'cd /data/db; mongodump' sudo docker stop some-mongo sudo docker rm some-mongo # Load upgraded data into latest version of MongoDB (WiredTiger storage engine will be used) mongorestore /data/db/dump sudo rm -rf /data 
+8
source

All Articles