By doing the following aggregation quey:
db.pings.aggreagte(
{"$project": {month: {"$month": "$timestamp"}, machineName: 1, timestamp: 1}},
{"$match":{month: month}},
{"$sort":{"_id":1}},
{"$group":{_id:{machineName: "$machineName", day:{ "$dayOfMonth": "$timestamp"}}, first: {"$min":"$timestamp"}, last: {"$max":"$timestamp"}}}
);
I succeed to return the following result:
[ { _id: { machineName: 'DESKTOP-SH14Q6B', day: 3 },
first: 2017-11-03T15:03:59.123Z,
last: 2017-11-03T16:17:43.110Z }
...
]
Now, for each result, I need to go to machines
collections and fetch the machine's IP,
I should do this join in application level or there is a reasonable way to fetch the IP in my aggregation query?