we have request to make time out Spring Mongo Template. we have written logic to make time out of the mongotemplate like the following way.(Here collections size is :20GB)
MongoTemplate mongoTemplate = springMongo.mongoTemplate("mydb");
Query myQuery = new Query();
myQuery.addCriteria(Criteria.where("item").is(100));
myQuery.maxTimeMsec(1000);
List<String> list = mongoTemplate.find(myQuery,
String.class, "ObjectSavingTest");
the above call to mongodb is not making time out(Here the collection size is 20GB).
when we work with mongo java driver directly it is able to make time with the following code.
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("mydb");
// get a single collection
DBCollection collection = db.getCollection("ObjectSavingTest");
System.out.println(collection.count());
System.out.println("Checking DB");
BasicDBObject gtQuery = new BasicDBObject();
gtQuery.put("item", new BasicDBObject("$eq", 100));
DBCursor cursor5 = collection.find(gtQuery).maxTime(1000, TimeUnit.MILLISECONDS);
while (cursor5.hasNext()) {
System.out.println(cursor5.next());
}
System.out.println("Done");
} catch (MongoExecutionTimeoutException ex) {
ex.printStackTrace();
}
Need help in the Spring Mongo , why it is not able to make timeout at the specified time(milliseconds).