$currentDate
On this page
Definition
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.
Syntax
The $currentDate
expression is an empty object {}
and has no
internal syntax.
Behavior
Pass $currentDate: {}
as the value of any expression which accepts
an ISODate value.
Examples
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 }