[JAVA-4045] Change Events with more accurate time value Created: 14/Mar/21  Updated: 25/Aug/23  Resolved: 16/Mar/21

Status: Closed
Project: Java Driver
Component/s: Change Streams
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: O Z Assignee: Valentin Kavalenka
Resolution: Declined Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-56730 Improve Change Streams API timestamp ... Closed

 Description   

When reading change stream, the change event has time field "clusterTime" in seconds.

The request is to get a more accurate time, e.g. milliseconds.

 

https://docs.mongodb.com/manual/reference/change-events/



 Comments   
Comment by Valentin Kavalenka [ 16/Mar/21 ]

Hi oren.zvuluny@qlik.com,

There are two important things to note with regard to the clusterTime (ChangeStreamDocument.getClusterTime):

  1. Despite its BSON type is called Timestamp, it is a logical internal timestamp1. It is not associated with a regular Date type (see BSON timestamps).
  2. A driver has no control over the clusterTime value and resolution: the value is controlled by the MongoDB server, the resolution is set as part of the BSON Timestamp specification.

Thus, not only we cannot change the resolution of clusterTime, but also it should not be relevant to applications that use MongoDB. clusterTime should not be interpreted as a physical timestamp. clusterTime from change stream documents should only be used to partially order the reported changes. The order is partial and not total because changes caused by the same transaction have the same clusterTime.


1 See operationTime in command response for more details. But please keep in mind, that despite this operationTime also represents a logical time of a command, its value is different from the one specified in a change stream document.

Generated at Thu Feb 08 09:01:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.