Created
February 21, 2023 15:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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