Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Created February 21, 2023 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmoranga/f1ab2edfff01fc79d93582a52dd89cc3 to your computer and use it in GitHub Desktop.
Save pmoranga/f1ab2edfff01fc79d93582a52dd89cc3 to your computer and use it in GitHub Desktop.
On a mongo 3.6, group items by month from field with timestamp value
db.getCollection('Flights').aggregate([
{ $match: {"airport_code" : "AMS"}}
,{"$group": {"_id":
{ $dateToString: {
date: {"$add": [new Date(0),
{"$multiply": ["$created_at",1000 ]}
] } ,
format: "%Y-%m"}
}
, "count": {"$sum": 1}}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment