Re: query too slow

34 views
Skip to first unread message

Patrick Matsumura

unread,
Nov 8, 2012, 6:11:44 AM11/8/12
to mongo...@googlegroups.com
Hi Rodrigo

You should try to omit the call to the where function, since you're not really filtering. Also set an index on the data_captura field like this:

db.mentions.ensureIndex({data_captura: -1})

This should solve the problem with your slow query.

Hope this helps.

Patrick



On Wednesday, November 7, 2012 7:17:29 PM UTC+1, Rodrigo Coutinho wrote:
Hi,

I have the fallowing model and when this query is executed, it takes 1.1 s.
Other app is using the same database and performs this query with 0.3 s(PHP) .
Don't know what else to do, i've tried to change this query many times and still slow, despite the 200k documents.
help please


class Mention
include MongoMapper::Document

        def all (options = {})
             mentions = Mention.where({}).sort(:data_captura.desc).paginate(:per_page => 15, :page => 2).all
        end
end

Here's the output of the explain method:

=> {"cursor"=>"BasicCursor", "nscanned"=>214618, "nscannedObjects"=>214618, "n"=>15, "scanAndOrder"=>true, "millis"=>557, "indexBounds"=>{}, "allPlans"=>[{"cursor"=>"BasicCursor", "indexBounds"=>{}}], "oldPlan"=>{"cursor"=>"BasicCursor", "indexBounds"=>{}}} 
Reply all
Reply to author
Forward
0 new messages