CSHARP-5998: RawBsonDocument refactoring/removal - #2085
Conversation
There was a problem hiding this comment.
Pull request overview
Removes RawBsonDocument usage from the Change Streams core operation/cursor path by having the aggregate operation return typed results (TResult) directly, and updates the associated unit tests to match.
Changes:
- Refactor
ChangeStreamOperation<TResult>to create/executeAggregateOperation<TResult>using_resultSerializerinstead ofRawBsonDocumentSerializer. - Refactor
ChangeStreamCursor<TDocument>to wrapIAsyncCursor<TDocument>directly (removing raw BSON deserialization/disposal and the per-document resume token field). - Update Change Streams operation/cursor tests to align with the new typed cursor/serializer behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/MongoDB.Driver/Core/Operations/ChangeStreamOperation.cs |
Switches change stream aggregation/resume to operate on TResult cursors and uses the configured result serializer. |
src/MongoDB.Driver/Core/Operations/ChangeStreamCursor.cs |
Updates cursor implementation to consume IAsyncCursor<TDocument> directly and simplifies batch processing/token tracking. |
tests/MongoDB.Driver.Tests/Core/Operations/ChangeStreamOperationTests.cs |
Adjusts expectations/reflector types to match the new aggregate result serializer and generic operation type. |
tests/MongoDB.Driver.Tests/Core/Operations/ChangeStreamCursorTests.cs |
Partially updates tests for the new cursor constructor/signature and removes raw-deserialization-based assertions. |
Comments suppressed due to low confidence (4)
tests/MongoDB.Driver.Tests/Core/Operations/ChangeStreamCursorTests.cs:137
- This test still constructs
IAsyncCursor<RawBsonDocument>, but the updatedChangeStreamCursor<BsonDocument>constructor requiresIAsyncCursor<BsonDocument>.
var cursor = new Mock<IAsyncCursor<RawBsonDocument>>().Object;
tests/MongoDB.Driver.Tests/Core/Operations/ChangeStreamCursorTests.cs:152
- This test still constructs
IAsyncCursor<RawBsonDocument>, but the updatedChangeStreamCursor<BsonDocument>constructor requiresIAsyncCursor<BsonDocument>.
var cursor = new Mock<IAsyncCursor<RawBsonDocument>>().Object;
tests/MongoDB.Driver.Tests/Core/Operations/ChangeStreamCursorTests.cs:167
- This test still constructs
IAsyncCursor<RawBsonDocument>, but the updatedChangeStreamCursor<BsonDocument>constructor requiresIAsyncCursor<BsonDocument>.
var cursor = new Mock<IAsyncCursor<RawBsonDocument>>().Object;
tests/MongoDB.Driver.Tests/Core/Operations/ChangeStreamCursorTests.cs:496
CreateSubjectnow takesIAsyncCursor<BsonDocument>, but several tests in this file still create/passMock<IAsyncCursor<RawBsonDocument>>(e.g., in the Dispose/DisposeAsync tests). Those call sites will not compile after the cursor type change and should be updated toIAsyncCursor<BsonDocument>.
private ChangeStreamCursor<BsonDocument> CreateSubject(
IAsyncCursor<BsonDocument> cursor = null,
IReadBinding binding = null,
ICoreSessionHandle session = null,
IChangeStreamOperation<BsonDocument> changeStreamOperation = null,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -86,7 +81,6 @@ public void ChangeStreamOperation_should_have_expected_change_stream_operation_o | |||
| public void constructor_should_initialize_instance() | |||
| { | |||
| var cursor = new Mock<IAsyncCursor<RawBsonDocument>>().Object; | |||
| var firstDocument = BsonDocument.Parse("{ _id : { resumeToken : 1 }, operationType : 'insert', ns : { db : 'db', coll : 'coll' }, documentKey : { _id : 1 }, fullDocument : { _id : 1 } }"); | ||
| var firstBatch = new[] { ToRawDocument(firstDocument) }; | ||
| mockCursor.Setup(c => c.MoveNext(It.IsAny<CancellationToken>())).Returns(true); | ||
| mockCursor.SetupGet(c => c.Current).Returns(firstBatch); |
| if (hasMore) | ||
| { | ||
| try | ||
| { | ||
| _current = DeserializeDocuments(_cursor.Current); | ||
| } | ||
| finally | ||
| { | ||
| foreach (var rawDocument in _cursor.Current) | ||
| { | ||
| rawDocument.Dispose(); | ||
| } | ||
| } | ||
| _current = _cursor.Current; | ||
| _postBatchResumeToken = ((ICursorBatchInfo)_cursor).PostBatchResumeToken; | ||
| } |
| public static ChangeStreamCursor<TDocument>.ResumeValues GetResumeValues<TDocument>(this IChangeStreamCursor<TDocument> cursor) => | ||
| (ChangeStreamCursor<TDocument>.ResumeValues)Reflector.Invoke(cursor, nameof(GetResumeValues)); |
BorisDog
left a comment
There was a problem hiding this comment.
LGTM, just need to double check that PostBatchResumeToken is always present.
Part 2 of the RawBsonDocument deprecation work: remove RawBsonDocument from ChangeStreams.