How to optimize mongo aggregate query with date + count

Viewed 41

I have a query that takes around 10 seconds and looks like this:

db.collection.aggregate([
  { $match: { date: { $gt: before } } },
  {
    $group: {
      _id: "$address",
      count: { $sum: 1 },
    }
  }
])

When I add an index:

db.collection.createIndex({date: 1, address: 1})

I expected it to improve performance but nothing changed. I there anything else I can to to improve the time?

Would a timestamp perform better here than ISODate ?

0 Answers
Related