com.mongodb.MongoTimeoutException

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

If MongoDB is installed on the same instance as your app, use localhost to connect to MongoDB, e.g. 127.0.0.1:27017.

tip

You should init MongoClient only once.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • {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}
    via by Jyoti Das,
  • {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}
    via by Jyoti Das,
  • MongoDB YCSB: Connection error
    via Stack Overflow by Astro
    ,
  • Mongo timed out on save
    via Stack Overflow by ianaz
    ,
    • 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)

    Users with the same issue

    rocday
    1 times, last one,
    linxiaolong
    64 times, last one,
    Unknown visitor1 times, last one,
    nasimk
    536 times, last one,
    Unknown visitor1 times, last one,
    17 more bugmates