search

Home  >  Q&A  >  body text

MongoDB 如何修改数据库名称

如题,在命令行里运行修改已有数据库名称

怪我咯怪我咯2860 days ago845

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-24 09:14:28

    There is no direct method, only copy and then delete:

    db.copyDatabase('old_name', 'new_name'); 
    use old_name 
    db.dropDatabase(); 

    ==2017.4.4 Update==
    is still an indirect solution, but WiredTigerthere is a more convenient solution for the storage engine: db.renameCollection.

    use admin;
    db.runCommand({renameCollection: "test.test", to: "test1.test"});

    When you move all collections to a new library, it is equivalent to renaming the entire library. This will be much faster than copyDatabase.

    Note: renameCollection cannot be used for shard sets

    reply
    0
  • 阿神

    阿神2017-04-24 09:14:28

    db.help()

    reply
    0
  • Cancelreply