Skip to content

feat(mongo): modernize driver with SDAM, sessions, and wire features - #2880

Closed
gedaiu wants to merge 90 commits into
vibe-d:masterfrom
gedaiu:gis-main
Closed

feat(mongo): modernize driver with SDAM, sessions, and wire features#2880
gedaiu wants to merge 90 commits into
vibe-d:masterfrom
gedaiu:gis-main

Conversation

@gedaiu

@gedaiu gedaiu commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Brings the MongoDB driver up to modern server-spec compliance so it can run reliably against replica sets and current MongoDB releases: SDAM-based topology monitoring with primary step-down recovery, server sessions with retryable writes and multi-document transactions, and per-query read preferences. On top of that it adds change streams, mongodb+srv seedlist resolution, load-balanced mode, Stable API, OP_COMPRESSED wire compression, client-side field level encryption, GridFS, and MongoDB 8.0 server-level bulkWrite, each backed by integration tests under tests/mongodb. Also fixes estimatedDocumentCount on missing collections and switches to X.509 auth when an SSL key file is configured.

Fixes #2845, fixes #2846, fixes #2847, fixes #2848, fixes #2849, fixes #2850, fixes #2851, fixes #2854, fixes #2855, fixes #2856, fixes #2858, fixes #2859, fixes #2860, fixes #2861, fixes #2862, fixes #2863, fixes #2864.

gedaiu added 30 commits March 26, 2026 14:41
- Added compression helpers for negotiating compressors and (de)compressing OP_COMPRESSED payloads.
- Introduced ServerDescription struct to manage server state and topology, including classification of server types.
- Implemented wire protocol primitives for message length computation and OP_MSG body parsing.
- Established wire-version compatibility with UDAs for enforcing version constraints on nullable fields.
- Added comprehensive unit tests for all new functionalities to ensure correctness and reliability.
gedaiu added 28 commits June 12, 2026 01:05
…ror is not masked by abort failure

feat(serversession): add dirty state management to handle network errors in sessions
feat(tests): update run script to ensure standalone mongod is always started for negative path testing
…s and enhance selectServer logic with tagSets support
…tion improvements

- Updated `MongoCursor` to include `readPreferenceTags` in the `buildFindCommand` method, ensuring correct handling of read preferences during cursor operations.
- Modified `buildFindCommand` and `buildAggregateCommand` to accept `tagSets`, allowing for more precise read preference configurations.
- Implemented validation in `applySrvSeedlist` to reject multiple TXT records and ensure correct load-balanced configurations.
- Added unit tests to verify that read preference tags are correctly included in commands and that SRV resolution behaves as expected.
- Enhanced `MongoClientSettings` to track whether `loadBalanced` was explicitly set in the connection string, preventing unintended overrides from TXT records.
…ed IDs in bulk operations

feat(collection): modify InsertOneResult to support various BSON types for inserted IDs
feat(changestream): update documentation to clarify tailable cursor behavior in change streams
…ent validation errors

feat(serversession): implement destructor for MongoClientSession to ensure session cleanup on shutdown
… keys and enhance ClientEncryption with key vault integration
- Added concurrency contract documentation for MongoClient to clarify thread safety.
- Implemented bulk write command partitioning to respect server limits on write operations.
- Introduced methods to handle orphaned cursors during bulk write operations.
- Enhanced session pool timeout handling based on server capabilities.
- Improved topology management by pruning stale connection pools.
- Added support for detecting invalidate events in change streams and managing resume points accordingly.
- Updated encryption validation to enforce key length requirements for local KMS providers.
- Enhanced retryable writes logic to ensure bulkWrite commands are only retried when appropriate.
- Improved load balancer readiness checks in test scripts.
- Updated session timeout tests to reflect server-advertised values.
vibe-serialization 1.2.0 dropped the implicit BsonObjectID->Bson
conversion in Bson.opEquals; insertResults[0].insertedId is a Bson,
so the comparison must wrap the BsonObjectID. Fixes the bulkwrite
integration test failing to compile under dmd/vibe-serialization 1.2.0.
MongoDB 3.6 rejects opening a $changeStream on a non-existent database
("cannot open $changeStream for non-existent database"); newer servers
tolerate a missing collection. runReplicaSetTest dropped the collection
then watched it, so the priming read failed on 3.6. Create the collection
explicitly after the drop. Verified against a real mongod 3.6.23 replica
set and the existing 7.0 run.sh path.
A default MongoDB 3.6 mongod advertises no wire compressors, so zlib is
never negotiated and no OP_COMPRESSED is ever sent. The reconnect-handshake
compression bug cannot manifest without compression, so turn the
OP_COMPRESSED precondition into a graceful skip instead of a hard assert.
Verified: skips on a real 3.6 standalone, runs the full assertion on 7.0.
Brings in 4 upstream commits (rest void-return Content-Type fix, SMTP
envelope sender). None touch mongodb/.
@gedaiu

gedaiu commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of a stacked, reviewable decomposition

Hey! This branch grew into a ~14k-line near-total rewrite of the MongoDB driver, which is far too large to review in one piece. I've split it into 9 focused, dependency-ordered PRs, each based on the current upstream master, each compiling on its own with unit tests green, and each closing specific tracked issues. Together they reproduce this branch exactly, so I'm closing it here and moving the work into the stack below (please review in order):

#2882 — MongoDB driver SDAM core: topology discovery, health monitoring, primary write-routing, per-query read preferences, read-preference tags. Closes #2845, #2847, #2848, #2849, #2851
#2883 — Client sessions, multi-document transactions, retryable writes. Closes #2854, #2855, #2856, #2850 · merge after #2882
#2884 — Change streams. Closes #2860 · merge after #2883
#2885 — Server-level bulkWrite. Closes #2861 · merge after #2884
#2886 — GridFS. Closes #2862 · merge after #2885
#2887 — CSFLE (client-side field level encryption). Closes #2863 · merge after #2886
#2888 — Stable API (Versioned API). Closes #2858 · merge after #2887
#2890 — Load-balancer mode. Closes #2864 · merge after #2888
#2889 — mongodb+srv:// connection strings. Closes #2859 · merge after #2890
Each PR's diff is scoped to a single feature, so they're small enough to review properly. Thanks for taking a look!

@gedaiu gedaiu closed this Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment