There is an timeout message to update a document on my mongodb.
What is wrong ?
Here is log message :
INFO: No server chosen by PrimaryServerSelector from cluster description ClusterDescription{ type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=14.0.xx.xxx:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
Below is java code:
MongoClient mongoClient = new MongoClient("14.0.xx.xxx", 27017); MongoDatabase db = client.getDatabase("axis"); String axisDate = axis.substring(0, 10); int axisHour = Integer.parseInt(axis_hour); String id = axisDate + "_" + gid + "_" + cname + "_" + axisHour; Document key = new Document("_id", id); Document value = new Document("$set", new Document("_id", id) .append("gid", gid) .append("service_name", cname) .append("axis", axisDate) .append("axis_hour", axisHour) .append("bandwidth", bandwidth) .append("peak", peak)); UpdateOptions uo = new UpdateOptions(); try { UpdateResult rs = db.getCollection("video_cdn_traffic_log").updateOne(key, value, uo.upsert(true)); }catch (MongoWriteException e) { e.printStackTrace(); }catch (MongoWriteConcernException e) { e.printStackTrace(); }catch (MongoException e) { e.printStackTrace(); }finally{ client.close(); }