com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms

JIRA | Jyoti Das | 2 years ago
  1. 0

    {noformat} Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms at com.mongodb.BaseCluster.getServer(BaseCluster.java:87) at com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:654) at com.mongodb.DBTCPConnector.access$300(DBTCPConnector.java:39) at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:503) at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:451) at com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:409) at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:182) at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:165) at com.mongodb.DBCollection.insert(DBCollection.java:161) at com.mongodb.DBCollection.insert(DBCollection.java:107) at com.mongodb.DBCollection.save(DBCollection.java:966) at com.mongodb.DBCollection.save(DBCollection.java:934) at com.mongodb.gridfs.GridFSInputFile._dumpBuffer(GridFSInputFile.java:281) at com.mongodb.gridfs.GridFSInputFile.saveChunks(GridFSInputFile.java:231) at com.mongodb.gridfs.GridFSInputFile.save(GridFSInputFile.java:177) at com.mongodb.gridfs.GridFSInputFile.save(GridFSInputFile.java:158) at es.db.mongodb.MongodbTest.main(MongodbTest.java:76) {noformat} The code: {code:java} public class MongodbTest { public static void main(String[] args) throws IOException { System.out.println("Entered mongotest"); MongoClient mongoClient = new MongoClient("192.168.1.214", 27017); //http://api.mongodb.org/java/2.10.1/com/mongodb/MongoClient.html //A MongoDB client with internal connection pooling. For most applications, //you should have one MongoClient instance for the entire JVM. DB db = mongoClient.getDB("test"); DBCollection collection = db.getCollection("downloads_meta"); String filePath = "C:\\axd\\dell_fig1.jpg"; File file = new File(filePath); GridFS gridfs = new GridFS(db, "downloads"); GridFSInputFile gfsFile = gridfs.createFile(file); gfsFile.setFilename("dell_fig1.jpg"); gfsFile.save(); //It crashes here. BasicDBObject info = new BasicDBObject(); info.put("name", "Dell"); info.put("fileName", "dell_fig1.jpg"); info.put("rawName", "dell_fig1.jpg"); info.put("rawPath", "C:\\axd"); collection.insert(info, WriteConcern.SAFE); } } {code}

    JIRA | 2 years ago | Jyoti Das
    com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
  2. 0

    {noformat} Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms at com.mongodb.BaseCluster.getServer(BaseCluster.java:87) at com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:654) at com.mongodb.DBTCPConnector.access$300(DBTCPConnector.java:39) at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:503) at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:451) at com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:409) at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:182) at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:165) at com.mongodb.DBCollection.insert(DBCollection.java:161) at com.mongodb.DBCollection.insert(DBCollection.java:107) at com.mongodb.DBCollection.save(DBCollection.java:966) at com.mongodb.DBCollection.save(DBCollection.java:934) at com.mongodb.gridfs.GridFSInputFile._dumpBuffer(GridFSInputFile.java:281) at com.mongodb.gridfs.GridFSInputFile.saveChunks(GridFSInputFile.java:231) at com.mongodb.gridfs.GridFSInputFile.save(GridFSInputFile.java:177) at com.mongodb.gridfs.GridFSInputFile.save(GridFSInputFile.java:158) at es.db.mongodb.MongodbTest.main(MongodbTest.java:76) {noformat} The code: {code:java} public class MongodbTest { public static void main(String[] args) throws IOException { System.out.println("Entered mongotest"); MongoClient mongoClient = new MongoClient("192.168.1.214", 27017); //http://api.mongodb.org/java/2.10.1/com/mongodb/MongoClient.html //A MongoDB client with internal connection pooling. For most applications, //you should have one MongoClient instance for the entire JVM. DB db = mongoClient.getDB("test"); DBCollection collection = db.getCollection("downloads_meta"); String filePath = "C:\\axd\\dell_fig1.jpg"; File file = new File(filePath); GridFS gridfs = new GridFS(db, "downloads"); GridFSInputFile gfsFile = gridfs.createFile(file); gfsFile.setFilename("dell_fig1.jpg"); gfsFile.save(); //It crashes here. BasicDBObject info = new BasicDBObject(); info.put("name", "Dell"); info.put("fileName", "dell_fig1.jpg"); info.put("rawName", "dell_fig1.jpg"); info.put("rawPath", "C:\\axd"); collection.insert(info, WriteConcern.SAFE); } } {code}

    JIRA | 2 years ago | Jyoti Das
    com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms
  3. 0
    If MongoDB is installed on the same instance as your app, use localhost to connect to MongoDB, e.g. 127.0.0.1:27017.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    You should init MongoClient only once.
  6. 0

    MongoDB plugin - how to make it to not create a datasource during testing?

    Stack Overflow | 2 years ago | dic19
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. com.mongodb.MongoTimeoutException

      Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms

      at com.mongodb.BaseCluster.getServer()
    2. MongoDB Java Driver
      GridFSInputFile.save
      1. com.mongodb.BaseCluster.getServer(BaseCluster.java:87)
      2. com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:654)
      3. com.mongodb.DBTCPConnector.access$300(DBTCPConnector.java:39)
      4. com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:503)
      5. com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:451)
      6. com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:409)
      7. com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:182)
      8. com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:165)
      9. com.mongodb.DBCollection.insert(DBCollection.java:161)
      10. com.mongodb.DBCollection.insert(DBCollection.java:107)
      11. com.mongodb.DBCollection.save(DBCollection.java:966)
      12. com.mongodb.DBCollection.save(DBCollection.java:934)
      13. com.mongodb.gridfs.GridFSInputFile._dumpBuffer(GridFSInputFile.java:281)
      14. com.mongodb.gridfs.GridFSInputFile.saveChunks(GridFSInputFile.java:231)
      15. com.mongodb.gridfs.GridFSInputFile.save(GridFSInputFile.java:177)
      16. com.mongodb.gridfs.GridFSInputFile.save(GridFSInputFile.java:158)
      16 frames
    3. es.db.mongodb
      MongodbTest.main
      1. es.db.mongodb.MongodbTest.main(MongodbTest.java:76)
      1 frame