MongoDB 3 Java check if collection exists

后端 未结 6 426
醉酒成梦
醉酒成梦 2020-12-06 05:13

I have the following problem:

I\'m using the Java driver for MongoDB 3.

In version 2 it was possible to do DB.collectionExists(name) to check whether a colle

6条回答
  •  抹茶落季
    2020-12-06 05:46

    MongoIterable  collection =  database.listCollectionNames();
        for(String s : collection) {
            if(s.equals("collectionName")) {
                return true;
    
            }
        }
        return false;
    }
    

提交回复
热议问题