Amrit R Asher
Amrit R Asher

Reputation: 51

how to transfer mongodb database from one server to another server (both of them are linux)

So if I am hosting a MongoDB database in a Linux VM, then how can I transfer the database to another VM with the same data and structure. Also, I did some research and found out something like mongodump, but I didn't find any docs for that. So can someone give an explanation of how it works or show the docs for it

Upvotes: 0

Views: 1797

Answers (1)

zelmario
zelmario

Reputation: 96

Before Mongodb 4.0 you can use: db.copyDatabase() db.copyDatabase()

After Mongodb 4.0 you must use mongodump / mongorestore:

mongodump --archive="mongodump-test-db" --db=test

Copy the file from one server to another and then (with database name change):

mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'

There's a lot info here: mongodump-example-copy-clone-database

Upvotes: 1

Related Questions