Mongo timeout exception

I was looking for a watch and I can't figure out why this doesn't work, can you please give me guys? I am trying to implement mongodb in my project everything seems to be correct, but when I try to change / access it it gives me this "Mongo Timeout Exception".


    try {
        MongoCredential credential = MongoCredential.createCredential(USER, DATABASE, PASSWORD.toCharArray());
        MongoClient mongoClient = new MongoClient(new ServerAddress(HOST), Arrays.asList(credential));
        DB database = mongoClient.getDB(DATABASE);
        DBCollection collection = database.getCollection(COLLECTION);
        DBCursor cursor = collection.find();
        cursor.next();
        System.out.println("Success!");
    } catch(Exception ex) { ex.printStackTrace(); }

      


com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=104.236.68.242:27017, type=Unknown, state=Connecting}]
    at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128)
    at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:394)
    at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:571)
    at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:368)
    at com.mongodb.Mongo.isMongosConnection(Mongo.java:622)
    at com.mongodb.DBCursor._check(DBCursor.java:494)
    at com.mongodb.DBCursor._next(DBCursor.java:551)
    at com.mongodb.DBCursor.next(DBCursor.java:701)
    at net.Heiden.DB.Testing.main(Testing.java:29)

      

Any help counts. Thanks ^^

+3


source to share





All Articles