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

JIRA | Jyoti Das | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  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 | 3 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 | 3 years ago | Jyoti Das
    com.mongodb.MongoTimeoutException: Timed out while waiting for a server that matches AnyServerSelector{} after 10000 ms

    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