Commit 9099635d by jinfeng.wang

fix

parent 995e9e20
package com.mobvista.apptag.utils;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
......@@ -22,9 +24,20 @@ import java.util.Set;
public class GetPackageFromMongo {
public static void main(String[] args) {
try {
MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
// build the connection options,set the max wait time in (ms)
builder.maxConnectionIdleTime(60000);
MongoClientOptions opts = builder.build();
// MongoCredential credential2 = MongoCredential.createCredential("username", "databasename",password2);
//add your option to the connection
// MongoClient mongoClient = new MongoClient(new ServerAddress("server ip",27017), Arrays.asList(credential2),opts);
// 连接到 mongodb 服务
String mongoUrl = "internal-beijing-adServerMongo-virginia-1390640500.us-east-1.elb.amazonaws.com";
MongoClient mongoClient = new MongoClient(mongoUrl, 27017);
MongoClient mongoClient = new MongoClient(new ServerAddress(mongoUrl, 27017), opts);
// 连接到数据库
MongoDatabase mongoDatabase = mongoClient.getDatabase("new_adn");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment