[Snyk] Upgrade mongodb from 6.7.0 to 6.12.0 #633
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Snyk has created this PR to upgrade mongodb from 6.7.0 to 6.12.0.
ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.
The recommended version is 77 versions ahead of your current version.
The recommended version was released 23 days ago.
Release notes
Package name: mongodb
6.12.0 (2024-12-10)
The MongoDB Node.js team is pleased to announce version 6.12.0 of the
mongodbpackage!Release Notes
zstd@2.0 is now supported for zstd compression
The new @ mongodb-js/zstd@2.0 release can now be used with the driver for zstd compression.
Populate
ServerDescription.errorfield when primary marked staleWe now attach an error to the newly created ServerDescription object when marking a primary as stale. This helps with debugging SDAM issues when monitoring SDAM events.
BSON upgraded to v6.10.1
See: https://github.com/mongodb/js-bson/releases/tag/v6.10.1
Socket read stream set to object mode
Socket data was being read with a stream set to buffer mode when it should be set to object mode to prevent inaccurate data chunking, which may have caused message parsing errors in rare cases.
SOCKS5: MongoNetworkError wrap fix
If the driver encounters an error while connecting to a socks5 proxy, the driver wraps the socks5 error in a MongoNetworkError. In some circumstances, this resulted in the driver wrapping MongoNetworkErrors inside MongoNetworkErrors.
The driver no longer double wraps errors in MongoNetworkErrors.
Features
Bug Fixes
Documentation
We invite you to try the
mongodblibrary immediately, and report any issues to the NODE project.6.11.0 (2024-11-22)
The MongoDB Node.js team is pleased to announce version 6.11.0 of the
mongodbpackage!Release Notes
Client Side Operations Timeout (CSOT)
We've been working hard to try to simplify how setting timeouts works in the driver and are excited to finally put Client Side Operation Timeouts (CSOT) in your hands! We're looking forward to hearing your feedback on this new feature during its trial period in the driver, so feel free to file Improvements, Questions or Bug reports on our Jira Project or leave comments on this community forum thread: Node.js Driver 6.11 Forum Discussion!
CSOT is the common drivers solution for timing out the execution of an operation at the different stages of an operation's lifetime. At its simplest, CSOT allows you to specify one option,
timeoutMSthat determines when the driver will interrupt an operation and return a timeout error.For example, when executing a potentially long-running query, you would specify
timeoutMSas follows:Warning
This feature is experimental and subject to change at any time. We do not recommend using this feature in production applications until it is stable.
What's new?
timeoutMSThe main new option introduced with CSOT is the
timeoutMSoption. This option can be applied directly as a client option, as well as at the database, collection, session, transaction and operation layers, following the same inheritance behaviours as other driver options.When the
timeoutMSoption is specified, it will always take precedence over the following options:socketTimeoutMSwaitQueueTimeoutMSwTimeoutMSmaxTimeMSmaxCommitTimeMSNote, however that
timeoutMSDOES NOT unconditionally override theserverSelectionTimeoutMSoption.When
timeoutMSis specified, the duration of time allotted to the server selection and connection checkout portions of command execution is defined bymin(serverSelectionTimeoutMS, timeoutMS)if both are>0. A zero value for either timeout value represents an infinite timeout. A finite timeout will always be used unless both timeouts are specified as0. Note also that the driver has a default value forserverSelectionTimeoutMSof30000.After server selection and connection checkout are complete, the time remaining bounds the execution of the remainder of the operation.
Note
Specifying
timeoutMSis not a hard guarantee that an operation will take exactly the duration specified. In the circumstances identified below, the driver's internal cleanup logic can result in an operation exceeding the duration specified bytimeoutMS.AbstractCursor.toArray()- can take up to2 * timeoutMSin'cursorLifetimeMode'and(n+1) * timeoutMSwhen returning n batches in'iteration'modeAbstractCursor.[Symbol.asyncIterator]()- can take up to2 * timeoutMSin'cursorLifetimeMode'and (n+1)*timeoutMSwhen returning n batches in'iteration'modeMongoClient.bulkWrite()- can take up to 2 * timeoutMS in error scenarios when the driver must clean up cursors used internally.In the
AbstractCursor.toArraycase and theAbstractCursor.[Symbol.asyncIterator]case, this occurs as these methods close the cursor when they finish returning their documents. As detailed in the following section, this results in a refreshing of the timeout before sending thekillCursorscommand to close the cursor on the server.The
MongoClient.bulkWriteand autoencryption implementations use cursors under the hood and so inherit this issue.Cursors,
timeoutMSandtimeoutModeCursors require special handling with the new timout paradigm introduced here. Cursors can be configured to interact with CSOT in two ways.
The first,
'cursorLifetime'mode, uses thetimeoutMSto bound the entire lifetime of a cursor and is the default timeout mode for non-tailable cursors (find, aggregate*, listCollections, etc.). This means that the initialization of the cursor and all subsequentgetMorecalls MUST finish withintimeoutMSor a timeout error will be thrown. Note, however that the closing of a cursor, either as part of atoArray()call or manually via theclose()method resets the timeout before sending akillCursorsoperation to the server.e.g.
The second,
'iteration'mode, usestimeoutMSto bound eachnext/hasNext/tryNextcall, refreshing the timeout after each call completes. This is the default mode for all tailable cursors (tailable find cursors on capped collections, change streams, etc.). e.g.Note that
timeoutModeis also configurable on a per-cursor basis.GridFS and
timeoutMSGridFS streams interact with
timeoutMSin a similar manner to cursors in'cursorLifeTime'mode in thattimeoutMSbounds the entire lifetime of the stream.In addition,
GridFSBucket.find,GridFSBucket.renameandGridFSBucket.dropall support thetimeoutMSoption and behave in the same way as other operations.Sessions, Transactions,
timeoutMSanddefaultTimeoutMSClientSessions have a new option:
defaultTimeoutMS, which specifies thetimeoutMSvalue to use for:commitTransactionabortTransactionwithTransactionendSessionNote
If
defaultTimeoutMSis not specified, then it will inherit thetimeoutMSof the parentMongoClient.When using
ClientSession.withTransaction, thetimeoutMScan be configured either in the options on thewithTransactioncall or inherited from the session'sdefaultTimeoutMS. ThistimeoutMSwill apply to the entirety of thewithTransactioncallback provided that the session is correctly passed into each database operation. If the session is not passed into the operation, it will not respect the configured timeout. Also be aware that trying to override thetimeoutMSat the operation level for operations making use of the explicit session inside thewithTransactioncallback will result in an error being thrown.const coll = client.db('db').collection('coll');
// ❌ Incorrect; will throw an error
await session.withTransaction(async function(session) {
await coll.insertOne({x:1}, { session, timeoutMS: 600 });
})
// ❌ Incorrect; will not respect timeoutMS configured on session
await session.withTransaction(async function(session) {
await coll.insertOne({x:1}, {});
})
ClientEncryption and
timeoutMSThe
ClientEncryptionclass now supports thetimeoutMSoption. IftimeoutMSis provided when constructing aClientEncryptioninstance, it will be used to govern the lifetime of all operations performed on instance, otherwise, it will inherit from thetimeoutMSset on theMongoClientprovided to theClientEncryptionconstructor.If
timeoutMSis set on both the client and provided to ClientEncryption directly, the option provided toClientEncryptiontakes precedence.await encryption.createDataKey('local'); // will not take longer than 1_000ms
const encryption = new ClientEncryption(new MongoClient('localhost:27027', { timeoutMS: 1_000 }));
await encryption.createDataKey('local'); // will not take longer than 1_000ms
const encryption = new ClientEncryption(new MongoClient('localhost:27027', { timeoutMS: 5_000 }), { timeoutMS: 1_000 });
await encryption.createDataKey('local'); // will not take longer than 1_000ms
Limitations
At the time of writing, when using the driver's autoconnect feature alongside CSOT, the time taken for the command doing the autonnection will not be bound by the configured
timeoutMS. We made this design choice because the client's connection logic handles a number of potentially long-running I/O and other setup operations including reading certificate files, DNS lookups, instantiating server monitors, and launching external processes for client encryption.We recommend manually connecting the
MongoClientif intending to make use of CSOT, or otherwise ensuring that the driver is already connected when running commands that make use oftimeoutMS.// ❌ No guarantee to finish in specified time
await client.db('db').collection('coll').insertOne({x:1});
// ✔️ Will have expected behaviour
await client.connect();
await client.db('db').collection('coll').insertOne({x:1});
Explain helpers support
timeoutMSExplain helpers support timeoutMS:
Note
Providing a
maxTimeMSvalue with atimeoutMSvalue will throw errors.MONGODB-OIDC Authentication now supports Kubernetes Environments.
For k8s environments running in Amazon's EKS (Elastic Kubernetes Service), Google's GKE (Google Kubernetes Engine), or Azure's AKS (Azure Kubernetes Service) simply provide an
ENVIRONMENTauth mechanism property in the URI orMongoClientoptions of "k8s".Example:
BSON Binary Vector Support!
Checkout BSON's release notes for more information: https://github.com/mongodb/js-bson/releases/tag/v6.10.0
ConnectionClosedEvents always follow PoolClearedEvents
When Connection Monitoring and Pooling events are listened for,
ConnectionClosedEvents are now always emitted afterPoolClearEvents.Features
Bug Fixes
Performance Improvements
Documentation
We invite you to try the
mongodblibrary immediately, and report any issues to the NODE project.6.10.0 (2024-10-21)
The MongoDB Node.js team is pleased to announce version 6.10.0 of the
mongodbpackage!Release Notes
Warning
Server versions 3.6 and lower will get a compatibility error on connection and support for MONGODB-CR authentication is now also removed.
Support for new client bulkWrite API (8.0+)
A new bulk write API on the
MongoClientis now supported for users on server versions 8.0 and higher.This API is meant to replace the existing bulk write API on the
Collectionas it supports a bulkwrite across multiple databases and collections in a single call.
Usage
Users of this API call
MongoClient#bulkWriteand provide a list of bulk write models and options.The models have a structure as follows:
Insert One
Note that when no
_idfield is provided in the document, the driver will generate a BSONObjectIdautomatically.
Update One
Update Many
Note that write errors occuring with an update many model present are not retryable.
Replace One
Delete One
Delete Many
Note that write errors occuring with a delete many model present are not retryable.*
Example
Below is a mixed model example of using the new API:
The bulk write specific options that can be provided to the API are as follows:
ordered: Optional boolean that indicates the bulk write as ordered. Defaults to true.verboseResults: Optional boolean to indicate to provide verbose results. Defaults to false.bypassDocumentValidation: Optional boolean to bypass document validation rules. Defaults to false.let: Optional document of parameter names and values that can be accessed using $$var. No default.The object returned by the bulk write API is: