Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB databases migrating from one OS to another

I am building a web application in Python for which I need MongoDB. I have MongoDB installed on a Mac OS X. And for my app I want to have a Linux VPS. I wanted to know whether I could migrate MongoDB collections from Mac to Linux. Does endianess of the system causes problems? What else might? I am no expert in databases or operating systems. And if we can migrate, can someone point me towards a guide or procedure? Thanks in advance.

like image 652
Sushant Gupta Avatar asked Dec 09 '22 01:12

Sushant Gupta


2 Answers

You can just run mongoexport, which will dump your database to a file in either JSON or CSV format.

Then, on your new machine, you can run mongoimport with the input file you got from mongoexport, and everything should be there.

mongoexport: http://www.mongodb.org/display/DOCS/mongoexport

mongoimport: http://www.mongodb.org/display/DOCS/Import+Export+Tools?focusedCommentId=4554852#ImportExportTools-mongoimport

like image 63
btoconnor Avatar answered Dec 24 '22 07:12

btoconnor


While export and re-importing certainly works, this will recreate all the indices from scratch in the new location. For complex indices this could take days.

I wouldn't be surprised in the binary files are compatible - so I would first try shutting down the original server, copying over the entire data directory to the new location. Make sure you are running the exact same version of the mongo server software (e.g. 2.0.x, both 64-bit and both official binaries from 10gen, and with the same configuration options).

I'm pretty sure this will start correctly and all data AND indices will be ready to go. This is basically just taking a binary snapshot of your data files.

like image 24
Nic Cottrell Avatar answered Dec 24 '22 09:12

Nic Cottrell