I use mongoDB to store the query log and get some statistics about it. The objects that I store in mongoDB contain the query text, date, user, if the user clicked on some results, etc. etc.
Now I am trying to get all requests not clicked by the user on a specific day with java. My code is something like this:
DBObject query = new BasicDBObject(); BasicDBObject keys = new BasicDBObject(); keys.put("Query", 1); query.put("Date", new BasicDBObject("$gte", beginning.getTime()).append("$lte", end.getTime())); query.put("IsClick", false); ... DBCursor cur = mongoCollection.find(query, keys).batchSize(5000);
The query result contains about 20 thousand records that I need for iteration. the problem is that it takes minutes :( I do not think this is normal. From the server log I can see:
Wed Nov 16 16:28:40 query db.QueryLogRecordImpl ntoreturn:5000 reslen:252403 nscanned:59260 { Date: { $gte: 1283292000000, $lte: 1283378399999 }, IsClick: false } nreturned:5000 2055ms Wed Nov 16 16:28:40 getmore db.QueryLogRecordImpl cid:4312057226672898459 ntoreturn:5000 query: { Date: { $gte: 1283292000000, $lte: 1283378399999 }, IsClick: false } bytes:232421 nreturned:5000 170ms Wed Nov 16 16:30:27 getmore db.QueryLogRecordImpl cid:4312057226672898459 ntoreturn:5000 query: { Date: { $gte: 1283292000000, $lte: 1283378399999 }, IsClick: false } bytes:128015 nreturned:2661 --> 106059ms
Thus, loading the first fragment takes 2 seconds, the second 0.1 seconds, the third 106 seconds !!! strange .. I tried to change the batch size by creating indexes in Date and IsClick, rebooting the machine: P, but nothing. Where am I mistaken?
source share