Simple query taking long time to execute

Guys, Im running the following query:

const sales = await Sale.find({seller, "createdAt": {$gte: finalUnix}}).lean().exec();

seller is the ID of the seller, like a hash, and the createdAt is an unix timestamp.

So, the collection has a total of 21k documents and this query returns about 1.100 results. But the problem is that, it is taking about 15-20 seconds to complete and I think that’s a lot of time, because I dont have much documents and results.

My schema is:

const Sale = new mongoose.Schema({
    seller: {
        type: String,
        required: true,
    },
    product: {
        type: String,
        required: true,
    },
    comment: {
        type: String,
        required: true,
    },
    transaction: {
        type: Object
    },
    createdAt: {
        type: String,
        required: true,
    }
})

And that’s it. The transaction object stored there doesnt contain much information, (I mean, it is not heavy at all). What could be the problem?

Note: I don’t know if it can be the problem but my application is probably running other queries while this one is running. (Because I have scripts working 24/7 collecting and storing data).

Post the explain plan so that we have an idea of what is happening.

Hardware configuration is also of interest for performance issues.

Hey @foco_radiante,

As @steevej has mentioned, kindly post the explain plain for us to better understand and help you with the problem. I also noticed that your included schema snippet does not have any index declarations, which could be one of the reasons for the slow queries. I suggest adding the appropriate compound index to support that query if you are not already using them.

I also noticed you had a very similar discussion here as well:

Did this discussion help resolve this problem or something is still left to be resolved?

Regards,
Satyam

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.