I would like to have my aggregation query return a flat array instead of an array of objects exactly like .distinct() does.
Example Document:
{
type: 'pageview',
url: 'https://example.com/something',
visitorId: '5df7c38abbdb1506dc048451'
}
Example Aggregation:
db.accounts.events.aggregate( [
// First stage
{ $match: { url: 'https://example.com/something' } },
// Second stage
{ $group: { _id: "$visitorId", count: { $sum: 1 } } },
// Third stage
{ $match: { count: { $gt: 10 } } }
] )
Returns:
{ "_id" : ObjectId("5df7c38abbdb1506dc048451"), "count" : 13 }
{ "_id" : ObjectId("5df7c38abbdb1506dc048454"), "count" : 18 }
// ... and so forth
Should return:
[ ObjectId("5df7c38abbdb1506dc048451"), ObjectId("5df7c38abbdb1506dc048454") ]
I know that its fairly easy to do on the client side, but I wonder if mongodb is capable of doing it right within the aggregation as well.