How can I rename a collection in MongoDB?

后端 未结 5 757
醉梦人生
醉梦人生 2020-12-24 00:36

Is there a dead easy way to rename a collection in mongo? Something like:

db.originalCollectionName.rename(\'newCollectionName\');

And if

5条回答
  •  盖世英雄少女心
    2020-12-24 01:10

    Assume that the database name is "mytestdb" and collection name is "orders". collection name change to orders2015 The simplest way is,

    > use mytestdb
    > db.orders.renameCollection( "orders2015" )
    

    Note : db.collection.renameCollection() is not supported on sharded collections.

提交回复
热议问题