How can I transfer a mongodb database to another machine that cannot see the first one
I have a server that is having trouble talking to the outside world. I would like to get its mongodb contents to another server--but since the servers cannot talk to eachother db.copyDatabase() won't do.
Is there something like mysqldump where I could dump the db into a binary fil开发者_JAVA百科e, scp that somewhere, and then use that to populate another mongodb server?
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
精彩评论