-
Hi, I have been trying to create a dashboard on MongoDB data to show month to date (MTD) aggregates. I couldn't find any documentation for the syntax of "start of month" or "current month" in $humanTime. If anyone have any pointer, pleas help. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
hi @kd-am, The $humanTime format in Redash does not provide a direct option for "start of month" or "current month" as you mentioned. To achieve the desired functionality, you can use MongoDB's date aggregation operators to calculate the start of the current month dynamically within your MongoDB query.
Here's an example MongoDB aggregation query that calculates the start of the current month and performs further aggregations: db.collection.aggregate([
{
$match: {
dateField: {
$gte: {
$dateFromParts: {
year: { $year: "$$NOW" },
month: { $month: "$$NOW" },
day: 1,
hour: 0,
minute: 0,
second: 0,
millisecond: 0
}
}
}
}
},
// Additional aggregation stages for further calculations
// ...
]); |
Beta Was this translation helpful? Give feedback.
hi @kd-am,
The $humanTime format in Redash does not provide a direct option for "start of month" or "current month" as you mentioned.
To achieve the desired functionality, you can use MongoDB's date aggregation operators to calculate the start of the current month dynamically within your MongoDB query.
Here's an example MongoDB aggregation query that calculates the start of the current month and performs further aggregations: