Skip to content

Instantly share code, notes, and snippets.

@mikicho
Last active November 3, 2017 19:43
Show Gist options
  • Save mikicho/4f9c1d32783292223c7da2373d678deb to your computer and use it in GitHub Desktop.
Save mikicho/4f9c1d32783292223c7da2373d678deb to your computer and use it in GitHub Desktop.
check mongo boundries

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment