Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change collection name in mongodb

Tags:

mongodb

Changing the name of a collection in mongodb can be achieved by copy the documents in the collection to a new one and delete the original.

But is there a simpler way to change the name of a collection in mongodb?

like image 791
xiaohan2012 Avatar asked May 24 '12 05:05

xiaohan2012


3 Answers

db.oldname.renameCollection("newname")
like image 62
James Gan Avatar answered Sep 24 '22 14:09

James Gan


Really? No google search?
http://www.mongodb.org/display/DOCS/renameCollection+Command

> db.oldname.renameCollection("newname")
like image 32
jdi Avatar answered Sep 22 '22 14:09

jdi


db.oldCollectionName.renameCollection("NewCollectionName")

Check Manual here.

like image 27
Sadikhasan Avatar answered Sep 24 '22 14:09

Sadikhasan