Doom
Doom

Reputation: 1278

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.

The time to take a file with 100.000 row on collection that contains 400.000 record is 150 second. And the time to insert this file (23MB) for single row is 240 second, and if i use the single insert the time is 10 minutes.

Upvotes: 0

Views: 726

Answers (1)

Carlos Rodriguez
Carlos Rodriguez

Reputation: 883

The solution is GridFS, you need to put it into practice...

A convention for storing large files in a MongoDB database. All of the official MongoDB drivers support this convention, as does the mongofiles program.

Upvotes: 1

Related Questions