Answers for "how do i copy mongodb database"

1

mongodb clone database

# Dump db to a local folder
mongodump mongodb://user:pwd@localhost/old_name -o ./dump 

# Restore the db with the new name
mongorestore mongodb://user:pwd@localhost -d new_name ./dump/old_name

# Try this flag if you get an authentication error
--authenticationDatabase admin
Posted by: Guest on January-10-2021
-1

mongo copy database

Before MongoDB version 4.2
source_db.copyDatabase('destination_db')

After MongoDB version 4.2
mongodump --archive="mongodump-source-db" --db=source_db
mongorestore --archive="mongodump-source-db" --nsFrom='source_db.*' --nsTo='destination_db.*'

Or,

mongodump --archive --db=source_db | mongorestore --archive  --nsFrom='source_db.*' --nsTo='destination_db.*'
Posted by: Guest on June-07-2021

Code answers related to "how do i copy mongodb database"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language