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 file, scp that somewhere, and then use that to populate another mongodb server?
You have two options. One is to write a script to restructure the data before using mongoimport to import the data. Another approach could be to import the data into MongoDB and then run an aggregation pipeline to transform the data into your required structure.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With