How to connect to MongoDB 3.2 in Java with username and password?

前端 未结 2 1482
悲&欢浪女
悲&欢浪女 2020-12-30 13:37

I\'m using MongoDB 3.2 in my application. The code below demonstrates database initialization logic:

private void dbInit(String dbName) {

    String mongoCl         


        
2条回答
  •  滥情空心
    2020-12-30 13:54

    As MarkusWMahlberg correctly noted, it is necessary to note the database name in the connection string.

    For instance:

    String mongoClientURI = "mongodb://" + DB_SRV_USR + ":" + DB_SRV_PWD + "@" + DB_URL + ":" + DB_PORT + "/" + dbName;
    

提交回复
热议问题