Check if mongodb database exists?

前端 未结 9 1490
孤街浪徒
孤街浪徒 2020-12-14 21:58

Is there a possibility to check if a mongo database allready exists?

9条回答
  •  旧巷少年郎
    2020-12-14 22:27

    Try this, it worked for me (on Mac OSx)

    MongoClient mongoClient = new MongoClient("localhost");
    /** **/
    boolean dbExist =
        mongoClient.listDatabaseNames().
        into(new ArrayList()).contains("TEST");
    
    System.out.print(dbExist);
    

提交回复
热议问题