mongodb dump and pipe to other db name

Viewed 3194

Mongodb version 3.2.12. I have two local databases, "base1" and "base2"

I want to copy all data (all collections) from base1 over to base2, replacing everything there (like when dumping production to a dev environment).

Any pipe command (or other simple way) to do this?

I tried

mongodump --archive --db base1 | mongorestore --db base2 --archive

lists a lot of "writing base1.collectionname to archive on stdout", but nothing gets written to base2.

I also tried

mongodump --db base1 --gzip --archive=/path/to/file.gz
mongorestore --db base2 --gzip --archive=/path/to/file.gz

Dump works, restore just says "creating intents for archive", "done"

2 Answers

I come across the same issue and after some googling and search I found this post https://stackoverflow.com/a/43810346/3785901

I tried this command mentioned:

mongodump --host HOST:PORT --db SOURCE_DB --username USERNAME --password PASSWORD --archive | mongorestore --host HOST:PORT --nsFrom 'SOURCE_DB.*' --nsTo 'TARGET_DB.*' --username USERNAME --password PASSWORD  --archive --drop

and it works like a charm. It should work in your case, good luck.

Related