-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 2.24.0, 2.25.0
-
Component/s: Change Streams
-
None
-
Fully Compatible
-
Dotnet Drivers
-
Not Needed
-
Summary
Please provide a clear and concise description of the bug.
Property FullDocument of the ChangeStreamDocument<TDocument> does throw an exception if the underyling value of fullDocument is of type BsonNull.
There is a very similar property called FullDocumentBeforeChange that also has similar functionality, but it has an additional check for BsonNull. I think FullDocument just lacks this check.
The exception is the following:
System.InvalidCastException: 'Unable to cast object of type 'MongoDB.Bson.BsonNull' to type 'MongoDB.Bson.BsonDocument'.'
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
driver versions: 2.24 and 2.25.
replica set consists of 3 simple containerized instances of version 7.0
How to Reproduce
Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.
Try to retrieve ChancheStreamDocument<BsonDocument> from the actual stream or create the document manually (easier to set up). The idea is to set fullDocument and fullDocumentBeforeChange the properties in BackingDocument to BsonNull.
Example of the second approach (manual creation of ChangeStreamDocument<BsonDocument>):
Try to create a ChangeStreamDocument<BsonDocument> and initialize it with a BsonDocument with {"fullDocument", BsonNull.Value },
{"fullDocumentBeforeChange", BsonNull.Value } (as shown below). Later, check its FullDocumentBeforeChange (should be no error) and FullDocument (should be erroneous).
var bsonDocumentSerializer = BsonSerializer.SerializerRegistry.GetSerializer<BsonDocument>(); var csd = new ChangeStreamDocument<BsonDocument>(new BsonDocument() { {"fullDocument", BsonNull.Value }, {"fullDocumentBeforeChange", BsonNull.Value } }, bsonDocumentSerializer); var fullDocBeforeChange = csd.FullDocumentBeforeChange; // <----- no error var fullDocAfterChange = csd.FullDocument; // <----- InvalidCastException
Either
Additional Background
Please provide any additional background information that may be helpful in diagnosing the bug.