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).