如何从 Mongodb 的 Clustertime 中提取操作计数?

How do I extract operation count from Clustertime in Mongdob?

我的 objective 是从 MongoDB clustertime 中提取操作计数。

即换句话说,我如何在管道中获得这个“i”值?

目前我们这样“提取”时间:

$addFields: {
  clusterTimeAsDate: {
      $toDate: { $dateToString: { date: '$clusterTime' } },
  },
}  

假设问题是关于聚合的问题,v5.1 中将添加 $tsIncrement 运算符 https://jira.mongodb.org/browse/SERVER-56874

必须是这样的:

$addFields: {
  clusterTimeAsDate: {
      $toDate: { $dateToString: { date: '$clusterTime' } },
  },
  clusterTimeIncrement: { $tsIncrement: '$clusterTime' }
} 

文档:https://docs.mongodb.com/upcoming/reference/operator/aggregation/tsIncrement/#mongodb-expression-exp.-tsIncrement

更新

升级时使用$tsSecond转换为日期可能更有效。