定义
每当 Atlas Stream Processing 求值时,$currentDate 表达式均会返回流处理实例的系统时间。此举可确保您在流媒体数据管道中添加的时间字段对每条处理过的消息保持最新。
语法
$currentDate 表达式是一个空对象 {},并且没有内部语法。
行为
将 $currentDate: {} 作为接受 ISODate 值的任意表达式的值来传递。
示例
以下示例演示了 $currentDate 表达式的基本用法,以确保每个来自给定流处理器的输出文档的时间戳准确无误。
{ "$addFields": { "time1": { "$currentDate": {} } } }
{ "a": 1, "time1": ISODate("2025-01-24T11:57:22.033Z") }
您可以在流处理管道中多次使用 $currentDate 表达式,为流处理器中的不同阶段生成多个时间戳。
{ "$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 }