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


哎呀。

我使用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

6142
2017-10-18 17:40


起源



答案:


尝试db [“stats”]。find()和db [“stats”]。renameCollection('statssnapshots')。

你也可以做db.getCollection(“stats”)。find()。


15
2017-10-18 17:51



db.getCollection()是我需要的,谢谢! [“统计数据”]不起作用。 - Zane Claes
哇,我觉得我不会在mongo遇到这种问题。奇怪他们把这个方法放在db上。请删除db [“stats”],因为它只引用stats函数中的build。 - Jason Sebring


答案:


尝试db [“stats”]。find()和db [“stats”]。renameCollection('statssnapshots')。

你也可以做db.getCollection(“stats”)。find()。


15
2017-10-18 17:51



db.getCollection()是我需要的,谢谢! [“统计数据”]不起作用。 - Zane Claes
哇,我觉得我不会在mongo遇到这种问题。奇怪他们把这个方法放在db上。请删除db [“stats”],因为它只引用stats函数中的build。 - Jason Sebring