Re: Query optimisation: count() with quite slow

From: "'azzy _home' via mongodb-user" <mongodb-user@xxxxxxxxxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Thu, 12 May 2016 00:36:23 -0700 (PDT)
Why ads?
Yes, stopSchedules is an array of schedules where one of the field is 
lastETAResult. I tried your suggestion and got this:

-- with lastETAResult indexed

// db.tourCloudTest2.count({ $and: [{'scheduleInfo.stopSchedules.lastETAResultUnix':{$gte: from, $lte: until}},{'tour.stops.locationId': {$exists: 1}}]});
// Execution time: 5,0s
// Result:
433

// db.tourCloudTest2.count({ $and: [{'scheduleInfo.stopSchedules': { $elemMatch: { 'lastETAResultUnix': {$gte: from, $lte: until }} }},{'tour.stops.locationId': {$exists: 1}}]});
// Execution time: 5,0s
// Result:
433


-- without an index on lastETAResult

// db.tourCloudTest2.count({ $and: 
[{'scheduleInfo.stopSchedules.lastETAResultUnix':{$gte: from, $lte: 
until}},{'tour.stops.locationId': {$exists: 1}}]});
// Execution time: 0,5s
// Result:
433

// db.tourCloudTest2.count({ $and: [{'scheduleInfo.stopSchedules': { 
$elemMatch: { 'lastETAResultUnix': {$gte: from, $lte: until }} 
}},{'tour.stops.locationId': {$exists: 1}}]});
// Execution time: 0,5s
// Result:
433

Regards,




-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/11c76172-b3ff-4533-9313-859d1eda374d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Why ads?