我不小心在MongoDB中命名了一个集合"stats",现在无法重命名它

Zan*_*aes 12 mongodb

哎呀.

我使用mongoose,并意外地创建了一个集合"stats".直到几周后我才意识到这将成为一个问题,所以我现在需要重命名(而不是仅删除)该集合......

但是,我的尝试遇到了一个可预测的问题:

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
Run Code Online (Sandbox Code Playgroud)

Tad*_*all 16

尝试db ["stats"].find()和db ["stats"].renameCollection('statssnapshots').

你也可以做db.getCollection("stats").find().

  • db.getCollection()是我需要的,谢谢!["统计数据"]不起作用. (2认同)