MongoDB 3 Java check if collection exists

后端 未结 6 425
醉酒成梦
醉酒成梦 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:20

    for anyone still looking: Assuming you have MongoDatabase instance called "db"

    try {
            db.createCollection("myCol");
        } catch (MongoCommandException e) {
            System.err.println("Collection Exists");
        }
    

提交回复
热议问题