2 Комити e85a79871c ... 40de72c23d

Аутор SHA1 Порука Датум
  pzc 40de72c23d Merge branch 'master' of http://192.168.20.122:3000/root/qiyewechatApp пре 4 година
  pzc 81fd65a141 mongo 密码设置链接方式 пре 4 година
1 измењених фајлова са 5 додато и 1 уклоњено
  1. 5 1
      ymall/src/main/java/com/liangjian11/ymall/utils/MongoDBUtil.java

+ 5 - 1
ymall/src/main/java/com/liangjian11/ymall/utils/MongoDBUtil.java

@@ -2,6 +2,7 @@ package com.liangjian11.ymall.utils;
 
 
 import com.mongodb.MongoClient;
+import com.mongodb.MongoClientURI;
 import com.mongodb.MongoCredential;
 import com.mongodb.ServerAddress;
 import com.mongodb.client.FindIterable;
@@ -33,7 +34,10 @@ public class MongoDBUtil {
       List<MongoCredential> credentials = new ArrayList<>();
       MongoCredential mongoCredential = MongoCredential.createScramSha1Credential(username, database, password.toCharArray());
       credentials.add(mongoCredential);
-      MongoClient mongoClient = new MongoClient(adds, credentials);
+//      MongoClient mongoClient = new MongoClient(adds, credentials);
+      String mongoClientURI = "mongodb://"+username+":"+password+"@" + host + ":" + port;
+      MongoClientURI connectionString = new MongoClientURI(mongoClientURI);
+      MongoClient mongoClient = new MongoClient(connectionString);
       MongoDatabase mongoDatabase = mongoClient.getDatabase(database);
       return mongoDatabase;
     } else {