Mongorestore to a different database

后端 未结 4 1490
别跟我提以往
别跟我提以往 2020-12-13 17:20

In MongoDB, is it possible to dump a database and restore the content to a different database? For example like this:

mongodump --db db1 --out dumpdir
mongore         


        
4条回答
  •  無奈伤痛
    2020-12-13 17:52

    You need to actually point at the "database name" container directory "within" the output directory from the previous dump:

    mongorestore -d db2 dumpdir/db1
    

    And usually just is fine as a positional argument rather than with -dir which would only be needed when "out of position" i.e "in the middle of the arguments list".

    p.s. For archive backup file (tested with mongorestore v3.4.10)

    mongorestore --gzip --archive=${BACKUP_FILE_GZ} --nsFrom "${DB_NAME}.*" --nsTo "${DB_NAME_RESTORE}.*"
    

提交回复
热议问题