Docs Menu
Docs Home
/
MongoDB Atlas
/ /

$currentDate

On this page

  • Definition
  • Syntax
  • Behavior
  • Examples

The $currentDate expression returns the system time of your stream processing instance each time Atlas Stream Processing evaluates it. This ensures that time fields you add from within a streaming data pipeline remain up-to-date for each processed message.

$currentDate

A $currentDate expression takes the form of an empty object {}.

The $currentDate expression is an empty object {} and has no internal syntax.

Pass $currentDate: {} as the value of any expression which accepts an ISODate value.

The following example demonstrates a basic use of the $currentDate expression to ensure accurate timestamps for each output document from a given stream processor.

{
"$addFields": {
"time1": {
"$currentDate": {}
}
}
}
{
"a": 1,
"time1": ISODate("2025-01-24T11:57:22.033Z")
}

You can use the $currentDate expression multiple times in your stream processing pipeline to generate multiple timestamps for various stags within a stream processor.

{
"$addFields": {
"time1": {
"$currentDate": {}
}
},
"$group": {
"_id": "$time1",
"count": {
"$count": {}
}
},
"$addFields": {
"time1": "$_id",
"time2": {
"$currentDate": {}
}
}
}
{
"time1": ISODate("2025-01-24T11:57:22.033Z"),
"time2": ISODate("2025-01-24T11:57:26.036Z"),
"count": 1
}

Back

$convert