Java MongoDAO 初始化
[Java]代码
private DB getMongoDB() { try { if (MONGODB_DB == null) { Mongo mgo = new Mongo(ip, port); DB db = mgo.getDB(mongodbName); char[] pwd = password.toCharArray(); db.authenticate(user, pwd); MongoOptions options = mgo.getMongoOptions(); options.socketTimeout = 2000; options.autoConnectRetry = true; options.socketKeepAlive = true; db.addOption(Bytes.QUERYOPTION_NOTIMEOUT); MONGODB_DB = db; return db; } else { return MONGODB_DB; } } catch (Exception e) { e.printStackTrace(); return null; } }