feat(server-services): upgrade mongodb driver from v5 to v6#27243
feat(server-services): upgrade mongodb driver from v5 to v6#27243zhajie wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Upgrades `@fluidframework/server-services` mongodb dependency from
`^5.9.2` to `^6.21.0` and fixes all v5→v6 breaking changes in the
MongoDB wrapper layer.
## Breaking changes addressed
### 1. `findOneAndUpdate` return type change
In v6, `findOneAndUpdate` / `findOneAndReplace` / `findOneAndDelete`
return the document directly (`T | null`) instead of a `ModifyResult`
wrapper object. The old `result.value` access pattern no longer works
unless `includeResultMetadata: true` is passed.
Fixed in `MongoCollection.findOrCreate` and `MongoCollection.findAndUpdate`
by accessing the result directly instead of via `.value`.
### 2. `returnOriginal` option removed
The `returnOriginal` option was removed in v6 in favor of
`returnDocument: "before" | "after"`.
Fixed in `MongoCollection.findOrCreate` default options:
- Before: `{ returnOriginal: true, upsert: true }`
- After: `{ returnDocument: "before" as const, upsert: true }`
### 3. `keepAlive` removed from `MongoClientOptions`
The `keepAlive` boolean option was removed from `MongoClientOptions`
in v6 (`keepAliveInitialDelay` remains valid and is unchanged).
Fixed in `MongoDbFactory.connect` by removing the `keepAlive: true` line.
## Dependency changes (v5 → v6)
- `bson`: 5.5.1 → 6.10.4
- `mongodb-connection-string-url`: 2.6.0 → 3.0.2
- `@mongodb-js/saslprep`: moved from optional to required (1.1.1 → 1.4.11)
- `socks`: moved from required to optional peer dependency
- `whatwg-url`: 11.0.0 → 14.2.0 (via mongodb-connection-string-url)
## Risk assessment
All MongoDB usage is centralized in `packages/services` behind the
`ICollection`/`IDb` abstraction interfaces, so downstream packages are
unaffected. No MapReduce, `Collection.count()`, or callback-based
`find()` calls exist in the codebase. `insertMany` already explicitly
sets `ordered: false`, making it independent of the v6 default change.
All 89 unit tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hi! Thank you for opening this PR. Want me to review it? Based on the diff (104 lines, 3 files), I've queued these reviewers:
How this works
|
🔭 PR Review Fleet ReportNote This report is generated by an experimental AI review fleet and is provided as a beta feature. Findings are a starting point for discussion, not a gate. Use your own judgement. Verdict: 0 Disastrous, 1 Dangerous, 0 Disagreeable Findings
|
| const options: MongoClientOptions = { | ||
| directConnection: this.directConnection ?? false, | ||
| keepAlive: true, | ||
| keepAliveInitialDelay: this.keepAliveInitialDelay, |
There was a problem hiding this comment.
keepAliveInitialDelay can be removed as well
| return result.value | ||
| ? { value: result.value, existing: true } | ||
| : { value, existing: false }; | ||
| return result ? { value: result as T, existing: true } : { value, existing: false }; |
There was a problem hiding this comment.
Let's do value: result as unknown as T, instead
- Use `result as unknown as T` instead of `result as T` in `MongoCollection.findOrCreate` and `MongoCollection.findAndUpdate` for safer type assertion through the unknown intermediate. - Remove `keepAliveInitialDelay` entirely: the option, its default constant, the config interface field, the class property, the constructor assignment, and the MongoClientOptions entry. TCP keep-alive configuration is not needed at the driver level. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Description
Upgrades the
mongodbNode.js driver in@fluidframework/server-servicesfrom
^5.9.2to^6.21.0and fixes all v5→v6 breaking changes in theMongoDB wrapper layer (
src/mongodb.ts).Breaking changes in the driver addressed
1.
findOneAndUpdatereturn type changeIn v6,
findOneAndUpdate/findOneAndReplace/findOneAndDeletereturnthe document directly (
T | null) instead of aModifyResultwrapper.Fixed in
MongoCollection.findOrCreateandMongoCollection.findAndUpdateby accessing the result directly instead of via
.value.2.
returnOriginaloption removedThe
returnOriginaloption was removed in v6 in favor ofreturnDocument: "before" | "after". Fixed inMongoCollection.findOrCreatedefault options:
{ returnOriginal: true, upsert: true }{ returnDocument: "before" as const, upsert: true }3.
keepAliveremoved fromMongoClientOptionsThe
keepAliveboolean was removed fromMongoClientOptionsin v6(
keepAliveInitialDelayremains valid). RemovedkeepAlive: truefromMongoDbFactory.connect.Transitive dependency changes
bson: 5.5.1 → 6.10.4mongodb-connection-string-url: 2.6.0 → 3.0.2@mongodb-js/saslprep: moved from optional to required (1.1.1 → 1.4.11)socks: moved from required to optional peer dependencywhatwg-url: 11.0.0 → 14.2.0 (via mongodb-connection-string-url)Reviewer Guidance
The review process is outlined on this wiki page.
All MongoDB usage is centralized in
packages/servicesbehind theICollection/IDbabstraction interfaces, so downstream packages areunaffected by the driver upgrade. No MapReduce,
Collection.count(), orcallback-based
find()calls exist in the codebase. All 89 unit tests pass.