java MongoDB RenameCollection

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

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);
}

Similar Posts: