gpt4 book ai didi

Mongotemplate 无法重命名集合

转载 作者:行者123 更新时间:2023-12-01 03:36:40 26 4
gpt4 key购买 nike

我有一个名为 collection_One 的集合.我想重命名集合,但失败了。 mongotemplate给我看了:

executing the 'renameCollection' command on the admin database"



如果我运行:
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);

最佳答案

String dbName = default;//mongo db 名称

MongoNamespace mongoNamespace=new MongoNamespace(dbName,"collection_two");
mongoTemplate.getCollection("collection_one").renameCollection(mongoNamespace);

字符串引导版本:2.1.4

关于Mongotemplate 无法重命名集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34161901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com