java MongoDB RenameCollection

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

private DBCollection renameCollection(String oldCollection, String newCollection) {
        if (!mongoTemplate.collectionExists(oldCollection))
            return null;
        if (mongoTemplate.collectionExists(newCollection))
            mongoTemplate.dropCollection(newCollection);
        DB db = mongoTemplate.getDb();
        DBCollection dbCollection = db.getCollection(oldCollection);
        return dbCollection.rename(newCollection, true);
}

转载于:https://my.oschina.net/u/588736/blog/891622

你可能感兴趣的:(java MongoDB RenameCollection)