I need the current date in a field within a project aggregation stage like this:
$project:{
todays_date: ''
}
I need some checks on basis of that below, I tried many things but they are not allowing me to add like this:
$project:{
todays_date: Date(),
}
but the date is from 1970.
Starting Mongo 4.2, you can use the new aggregation variable $$NOW which provides the current datetime:
db.collection.aggregate({ $project: { todays_date: "$$NOW" } })
// { todays_date: ISODate("2019-07-21T09:05:46.123Z") }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With