Tuesday 27 August 2013

Slow Find on Mongo DB

Slow Find on Mongo DB

Hi guys i have a problem with mongo, i have install mongodb following
documentation and, i use mongo with spring. I have insert on mongo 400000
row of a little of file:
List<LinkedHashmap<String,Object> listelem = contains all row of a file.
MongoTemplate mongo = new MongoTemplate(new MongoClient(), "mydb");
mongo.insert(list, "mycollection");
for(int i=0; i< list.size();i++){
mongo.insert(list.get(i), "mycollection");
}
I have use this solution because if i use:
mongo.insert(list, "mycollection");
and the content of file is >16MB is very slow to insert. (there is a
solution?)
If the i want find all row of a file i make this:
MongoTemplate mongo = null;
try {
mongo = new MongoTemplate(new MongoClient(), "mydb");
} catch (UnknownHostException e) {
e.printStackTrace();
}
Query search = new Query(Criteria.where("idfile").is(idfile));
List<BasicDBObject> listElem =
mongo.find(search,BasicDBObject.class,"mycollection");
But this find is very slow and i have insert index on db:
db.mycollection.ensureIndex( { "idfile": 1 } )
Where am I doing wrong? Thanks.

No comments:

Post a Comment