[JAVA-3225] ChangeStreamDocument does not have getters for txnNumber and lsid fields Created: 11/Mar/19  Updated: 28/Oct/23  Resolved: 22/Jul/19

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

Type: New Feature Priority: Major - P3
Reporter: Steve Choi (Inactive) Assignee: John Stewart (Inactive)
Resolution: Fixed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to DOCS-12588 Document implication of sharded txn o... Closed
Case:

 Description   

According to the ChangeStreamDocument api, there are no getter methods for txnNumber and lsid.

From the manual, these fields do exist when the operation is part of a transaction.

Would you be able to extend the ChangeStreamDocument class to include the above fields?

Is this related to CSHARP-2406?

I did try to implement my own POJO to use in ChangeStreamIterable.withDocumentClass(). I got as far as registering the class's codec into the MongoClient.codecRegistry(). However, I was not successful. If there is a recommended approach without using the getters, please let me know.



 Comments   
Comment by Githook User [ 22/Jul/19 ]

Author:

{'name': 'John Stewart', 'username': 'jstewart-mongo', 'email': 'john.stewart@mongodb.com'}

Message: Add getters for txnNumber and lsid fields to ChangeStreamDocument

JAVA-3225
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b6631daa8938810cbb99941bcb6b200a2c2ab071

Comment by Jeffrey Yemin [ 01/Apr/19 ]

alberto.forti@rbs.com, steve.choi

One important point about reliance on clusterTime: when transactions are supported in sharded clusters in MongoDB 4.2, it will be possible for multiple unrelated transactions executing on different shards to share the same cluster time, so it will be safer to rely on txnNumber and lsid to distinguish between unrelated transactions sharing the same cluster time. We will add properties for them in the next release.

Comment by Jeffrey Yemin [ 01/Apr/19 ]

Conclusion: Add

  • txnNumber
  • lsid

to ChangeStreamDocument

Comment by Alberto Forti [ 13/Mar/19 ]

Hi Jeff,

I'm trying to implement a materialized view of a collection updated with multi-document transactions. I was thinking of using the txnNumber in the change stream to identify changes beloging to the same transaction and replicate the same on the view. I've now realised that all changes belonging to the same transaction have the same ClusterTime and different transactions have different cluster times... so I think I can use the cluster time for that purpose. Can you please confirm? Thanks.

Comment by Jeffrey Yemin [ 11/Mar/19 ]

As a workaround, you can always decode into instances of the org.bson.Document class.

Comment by Jeffrey Yemin [ 11/Mar/19 ]

Hi steve.choi

I'm curious what you plan to do with those fields if you did have access to them.

Generated at Thu Feb 08 08:59:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.