|
@@ -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 {
|