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

mongodb

Solution

Try

db.getCollection("stats").find()

and

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

Problem

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 ```

Original source