Problem with mongorestore between mongodb2.4 and mongodb2.6

    Good day to all!


    Recently rebuilt the world in gentoo, which led to the mongoDB update. I launched the console, performed the usual mongodumpand mongorestore. I open my application and see a bunch of errors that some of the collections do not exist. Restarted mongodump, mongorestore, check the list of collections and see that out of the 50 collections, there is only ~ 30.

    I started to understand and came to the conclusion that the problem was as follows: mongodb2.4 is installed on the server, and mongodb2.6 is installed on me. My first thought was: quickly rebuild my mongu with version 2.4and enjoy life. This, as they say, is not kosher. I turned to Google for help, but I managed to find out only that in mongo2.6 we changed the logic of the collection creation team. Now you cannot use "size = null" and "max = null". But no solution to this problem was provided.

    And today, thanks to the prompt of Habrauser kuzma, a solution was found. Everything turned out and earned. Therefore, I decided to share it with everyone, maybe it will be useful to someone else.

    If the how-it-will-be-called-locally database (see below) does not exist yet, run the following command:

    mongo --eval "db.copyDatabase('remote-db-name','how-it-will-be-called-locally','server-address','user','password')"
    


    If the database already exists, it must be deleted before creation.

    mongo how-it-will-be-called-locally  --eval "db.dropDatabase(); db.copyDatabase('remote-db-name','how-it-will-be-called-locally', 'server-address','user','password')"
    


    The above code will copy the remote database remote-db-name and create a copy of it locally with the name how-it-will-be-called-locally.

    That's all.

    Also popular now: