How can I transfer a mongodb database to another machine that cannot see the first one
If you're using Ubuntu/Linux, run the following commands. First, mongodump
on the origin server:
mongodump --db DataBaseName
Copy the generated dump/DataBaseName
folder to the new machine. Then, import using mongorestore
:
mongorestore --db DataBaseName /path/to/DataBaseName
Note that /path/to/DataBaseName
should be a directory filled with .json and .bson representations of your data.
Use the mongodump and mongorestore commands.
mongodump --db test --collection collection
mongorestore --collection collection --db test dump/
You can also gzip. The documentation has more examples.
If you want to transfer database to another system, then you must use the following commands.
First dump the database to the output directory:
mongodump --db DatabaseName -o ./DirectoryName
then copy that directory and put it into your machine and issue this command:
mongorestore --db DBName ./DirectoryName