gpt4 book ai didi

java - com.mongodb.DB.authenticate(String,String) 是在内存中进行身份验证还是调用 mongo db?

转载 作者:行者123 更新时间:2023-12-01 22:43:29 24 4
gpt4 key购买 nike

我正在编写一个程序,其中我将 DB 设置为类中的静态变量,并且当我执行任何 CRUD 操作时,我在每个方法中使用此 db 变量。

public final class MongoDBUtil {

private static MongoClient ejClient = null;

private static DB db = null;

/**
* Prevent this class to creating the instance.
*/

private MongoDBUtil() {

}

public static DB getDB() {
if (db == null) {
String userName = Property.INSTANCE.get("mongo.username");
String pwd = Property.INSTANCE.get("mongo.pwd");
String dbName = Property.INSTANCE.get("mongo.database.name");

createMongoClient();

db = ejClient.getDB(dbName);

//db.authenticate will make a call to mongo db database or it's in memory call?

boolean auth = db.authenticate(userName, pwd.toCharArray());

if (!auth) {
throw new EJException("Authentication failed for mongo db.");
}
}
return db;
}
}

问题已放入代码中。

最佳答案

顺便说一句,该身份验证已在 2.12 中被弃用。您应该使用 MongoClient#MongoClient(java.util.List, java.util.List) 来代替。

关于java - com.mongodb.DB.authenticate(String,String) 是在内存中进行身份验证还是调用 mongo db?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25723369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com