Home > Mobile >  How do I extract operation count from Clustertime in Mongdob?
How do I extract operation count from Clustertime in Mongdob?

Time:11-25

My objective is to extract the operation count from MongoDB clustertime.

I.e. in other words, how do I get this "i" value in a pipeline?

enter image description here

Currently we "extract" the time like this:

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

CodePudding user response:

Assuming the question is about aggregation, there will be $tsIncrement operator added in v5.1 https://jira.mongodb.org/browse/SERVER-56874.

Must be something like this:

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

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

update

It might be more efficient to use $tsSecond to convert to Date when you upgrade.

  • Related