Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I accidentally named a collection "stats" in MongoDB and now cannot rename it

Tags:

mongodb

Oops.

I use mongoose, and accidentally created a collection "stats". I didn't realize this was going to be an issue until a few weeks later, so I now need to rename (rather than just delete) the collection...

However, my attempts have hit a predictable problem:

PRIMARY> db.stats.find();
Thu Oct 18 10:39:43 TypeError: db.stats.find is not a function (shell):1
PRIMARY> db.stats.renameCollection('statssnapshots');
Thu Oct 18 10:39:45 TypeError: db.stats.renameCollection is not a function (shell):1
like image 355
Zane Claes Avatar asked Oct 18 '12 17:10

Zane Claes


1 Answers

Try

db["stats"].find()

and

db["stats"].renameCollection('statssnapshots').

You could also do

db.getCollection("stats").find().
like image 109
Tad Marshall Avatar answered Sep 27 '22 01:09

Tad Marshall