I have MongoConnectionUtils this file I have dependecy below mongo-java-driver
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.0.0</version>
</dependency>
public class MongoConnectionUtils {
private static MongoDatabase db;
public synchronized static MongoDatabase getConnection() {
if (db != null) {
return db;
}
try {
String dbPath = Config.sharedInstance().value("db.path");
String dbUsername = Config.sharedInstance().value("db.username");
String dbPassword = Config.sharedInstance().value("db.password");
int dbPort = Integer.parseInt( Config.sharedInstance().value("db.port"));
String dbName = Config.sharedInstance().value("db.name");
MongoClient mongoClient = new MongoClient(dbPath, dbPort);
db=mongoClient.getDatabase(dbName);
} catch (Throwable e) {
}
return db;
}
}
previously i was using 2.10 jar but now using the latest version i found that db.getDB() is a deprecated method and i found getDatabase() method instead. So now i want to authenticate the DB with username and password. but i didn't find out db.auth() method. Please help.