我有一个名为collection_One
. 我想重命名集合,但失败了。mongotemplate
给我看了:
在 admin 数据库上执行“renameCollection”命令”
如果我运行:
db.collection_one.renameCollection("collection_one","collection_two");
在 mongo shell 中,它工作正常。
如何通过 mongotemplate 重命名集合?
这是我正在尝试的代码:
BasicDBObject basicObject = new BasicDBObject();
basicObject.append("renameCollection","collection_one");
basicObject.append("to","collection_two");
mongoTemplate.executeCommand(basicObject);