4

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"

henit
  • 1,150
  • 1
  • 12
  • 28

2 Answers2

7

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.

Edwin Cen
  • 161
  • 2
  • 7
0

I use following commands:

mongodump \
    --host ${mongo.host} \
    --port ${mongo.port} \
    --username ${mongo.backup_restore_user} \
    --password ${mongo.backup_restore_password} \
    --db ${mongo.db} \
    --gzip \
    --dumpDbUsersAndRoles \
    --archive=${archive}

and

mongorestore \
        --keepIndexVersion \
        --drop \
        --gzip \
        --restoreDbUsersAndRoles \
        --db ${mongo.db} \
        --host ${mongo.host} --port ${pims.mongo.port} \
        --username ${mongo.backup_restore_user} \
        --password ${mongo.backup_restore_password} \
        --archive=${archive}
Bor Laze
  • 2,458
  • 12
  • 20