search

Home  >  Q&A  >  body text

mongodb的data文件夹中内容直接复制到另一个mongodb的data文件夹中,是否可以直接使用呢?

作为迁移数据库的方法是否可行?

怪我咯怪我咯2757 days ago953

reply all(4)I'll reply

  • 黄舟

    黄舟2017-05-02 09:22:01

    Not recommended, something may go wrong and you will need to repair. You can use the mongorestore tool that comes with mongo to restore or migrate
    Chinese blog
    Official documentation

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-02 09:22:01

    If you want to copy the entire file, it is possible. For the WT engine, it must also be the entire folder, because WT has its own metadata. Just copying a few collections was useless in the past. MMAPv1 has no metadata, so in theory it is enough to copy all the files corresponding to a library. However, this is not supported and its correctness is not guaranteed.
    If you want to copy the entire folder, you must stop access to the entire database. The easiest way is to stop the instance. Of course it is not very practical in actual use, but you can stop dropping a secondary and then perform this operation. If you want to be faster, you can also use disk snapshots without stopping the instance, but the journal must be opened and the journal and data must be on the same disk.
    Copying folders works for both WT and MMAPv1.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-02 09:22:01

    It may not work, and I don’t recommend you do it. Sometimes there will be some unexpected problems. It is recommended to import through tools or commands

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-02 09:22:01

    Found some answers, hope they help you:
    Migrate mongodb database from localhost to remote servers

    reply
    0
  • Cancelreply