2 ms·
db.formEvent.aggregate([ { $match: { createdAt: {$gte: ISODate("whenever")}}}, { $group: { _id: "$custId", userAgents: { $addToSet: "$metadata.u
by squeaky-clean 8y ago
db.formEvent.aggregate([
{ $match: { createdAt: {$gte: ISODate("whenever")}}},
{ $group: { _id: "$custId", userAgents: { $addToSet: "$metadata.userAgent" } } },
{ $sort: { createdAt: -1 } }
])
Something like this? I'm not sure why this couldn't be an optimized query in mongo, but I'm also not sure why a query like this one needs to be optimized? This would run fast enough without needing indexes, and really fast with an index on a couple fields, but is a query like this run so frequently you need to have it be extremely optimized?