[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; }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/8959.html