$dateToString
Reference group: Date expressions
What it does
Formats a BSON Date as a string.
Syntax
{$dateToString: { date, format?, timezone?, onNull? }}
Use case
Report labels.
Important notes
Keep stored dates as BSON Date for filtering/sorting.
$dateToString: practical example
{ $project: { localDate: { $dateToString: { date: "$createdAt", format: "%Y-%m-%d %H:%M", timezone: "Asia/Kolkata" } } } }💡 Explanation
Formats a BSON Date as a string.
When to use it
Report labels.
Caution
Keep stored dates as BSON Date for filtering/sorting.
Key Takeaways
- Formats a BSON Date as a string.
- Typical use: Report labels.