Google Groups

very very very slow find query in mongo using java driver


hitesh kumar Apr 13, 2012 3:57 AM
Posted in group: mongodb-user
Hi I am using Win XP as operating system with 3 GB ram ,
 I am fetching data from a collection having around 86000 documents.

this is my query

 DBObject querynew = null;

            Mongo m = new Mongo("localhost",27017);
            DB db = m.getDB("employee_testing");
            DBCollection coll = db.getCollection("employee");
            str =  "Science" + ".*?$";
            DBObject A =
QueryBuilder.start("first_name").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject B =
QueryBuilder.start("last_name").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject C =
QueryBuilder.start("login_id").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject D =
QueryBuilder.start("sex").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject E =
QueryBuilder.start("contact_no").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject F =
QueryBuilder.start("date_of_birth").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject G =
QueryBuilder.start("city").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject H =
QueryBuilder.start("state").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject I =
QueryBuilder.start("country").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject J =
QueryBuilder.start("post_graduation").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject K =
QueryBuilder.start("post_stream").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject L =
QueryBuilder.start("post_graduation_campus").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject M =
QueryBuilder.start("post_graduation_marks").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject N =
QueryBuilder.start("graduation").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject O =
QueryBuilder.start("g_stream").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject P =
QueryBuilder.start("graduation_campus").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject Q =
QueryBuilder.start("other_graduation_campus").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject R =
QueryBuilder.start("graduation_marks").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject S =
QueryBuilder.start("town").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject T =
QueryBuilder.start("certification").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject U =
QueryBuilder.start("salary_range").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject V =
QueryBuilder.start("ext2").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject W =
QueryBuilder.start("ext3").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject X =
QueryBuilder.start("type").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject Y =
QueryBuilder.start("checked").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject Z =
QueryBuilder.start("last_exam_score").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject A1 =
QueryBuilder.start("exam_date").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject B1 =
QueryBuilder.start("password").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject C1 =
QueryBuilder.start("intermediate_marks").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject D1 =
QueryBuilder.start("matric_marks").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
            DBObject E1 =
QueryBuilder.start("university").is(Pattern.compile(str,
Pattern.CASE_INSENSITIVE)).get();
querynew =
QueryBuilder.start().or(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1,B1,C1,D1,E1).get();
BasicDBObject querymongo = (BasicDBObject)querynew;
DBCurcor = coll.find(querymongo).sort(new
BasicDBObject("first_name",-1)).limit(10);


it takes around 10 to 15 mins or sometimes even more to fetch only 10
document from 86000 documents, where as same query in MYSQL takes only
some mili-secound  to perform the same task;

Why it is happening..
Need help in making it lightning fast as it is the main feature of
mongodb.
I am having mongodb on my local system, so no sharding and all, I have
just install the mongodb and after that i just go to command prompt
and run the server by following command

c:\monodb\bin>mongod

so what to do to make query result fast.