$match写法:(重点处已经标红)
{ $match : { DTime : { $gte :ISODate('2019-03-07T16:00:00Z'),$lte :ISODate('2019-03-08T16:00:00Z') },$expr : {$eq: [ { $mod: [ { $second: '$DTime' }, 30 ] }, 0 ]} } }
注释:DTime为时间戳。 间隔30秒取一条数据。
本文详细介绍了如何使用MongoDB的$match操作符进行精确到30秒间隔的数据查询,通过设置时间戳范围和模运算,实现高效的时间过滤。
{ $match : { DTime : { $gte :ISODate('2019-03-07T16:00:00Z'),$lte :ISODate('2019-03-08T16:00:00Z') },$expr : {$eq: [ { $mod: [ { $second: '$DTime' }, 30 ] }, 0 ]} } }
注释:DTime为时间戳。 间隔30秒取一条数据。