MongoDb集合改名
public boolean mongoDbCollectionNameUpdate(String oldName,String newName){
/连接MongoDB数据库/
MongoClient mongoClient = MongoClients.create(mongourl);
MongoDatabase country = mongoClient.getDatabase("Country");
/判断是否存在该集合/
boolean collectionExists = country.listCollectionNames().into(new ArrayList
/改名/
if (collectionExists){
MongoCollection
collection.renameCollection(new MongoNamespace("Country",newName),new RenameCollectionOptions().dropTarget(false));
return true;
}
System.out.println("该集合不存在");
return false;
}
posted on 2023-03-14 20:30 brickMovingWorker 阅读(48) 评论(0) 收藏 举报
浙公网安备 33010602011771号