[Snyk] Upgrade mongodb from 3.5.9 to 6.13.0 #1456
Open
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 3.5.9 to 6.13.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 268 versions ahead of your current version.
The recommended version was released 21 days ago.
Issues fixed by the recommended upgrade:
SNYK-JS-BL-608877
Release notes
Package name: mongodb
6.13.0 (2025-01-30)
The MongoDB Node.js team is pleased to announce version 6.13.0 of the
mongodb
package!Release Notes
MongoDB Standardized Logging 📝
The driver's standardized logger is now available! The primary goal of our driver's logger is to enable insight into database operations without code changes so enabling and configuring the logger are primarily done through our environment variables.
TL;DR Show me the logs!
Tip
If you are a CLI app developer (or otherwise take great care of your std outputs): The client options constructor argument takes precedence over environment variables, permitting you to disable or otherwise customize the logger so your app does not automatically respond to the current environment.
Check out the in-depth logging docs here: https://www.mongodb.com/docs/drivers/node/current/fundamentals/logging/
🚀 Improved command monitoring performance
Previously, when command monitoring was enabled, the driver would make deep copies of command and reply objects, which have the potential to be very large documents. These copies have been eliminated, providing a speed and memory efficiency bump to command monitoring.
Warning
Since we no longer make deep copies of commands/replies in Command Monitoring Events, directly modifying the command/reply objects on
CommandStartedEvent
s andCommandSucceededEvent
s may lead to undefined behaviour.🧪 Experimental AbortSignal support added to Find and Aggregate! 🚥
A
signal
argument can now be passed to the following APIs:collection.find()
&collection.findOne()
collection.aggregate()
&collection.countDocuments()
In order to support field level encryption properly, also:
db.listCollections()
db.command()
When aborted, the signal will interrupt the execution of each of each of these APIs. For the cursor-based APIs, this will be observed when attempting to consume from the cursor via toArray(), next(), for-await, etc.
There is a known limitation: aborting a signal closes a perfectly healthy connection which can cause unnecessary connection reestablishment so we're releasing this as experimental for evaluation in use cases that can tolerate the shortcoming.
DNS SRV & TXT look up timeouts are retried
To mitigate the potentially transient DNS timeout error, the driver now catches and retries the DNS lookups upon resolving a
mongodb+srv://
style connection string.MongoClient.close now closes any outstanding cursors
Previously, cursors could somewhat live beyond the client they came from. What this meant was that depending on timing you would learn of the client's (and by proxy, the cursor's) demise via an assertion that the associated session had expired. This only occurred if your cursor needed to use the session, which only happens when it is attempting to run a
getMore
operation to obtain another batch of documents.Practically speaking a cursor that lives beyond a client is an exception waiting to happen, the connection pools are closed, the sessions are ended, last call has been served 🍻, it is only a matter of timing and event firing until the cursor learns of its fate and informs you by throwing an error via whatever API is being used (
.toArray()
,for-await
,.next()
).To make the expected state of cursors clearer in this scenario the
MongoClient
will now close any associated cursors upon itsclose()
-ing reducing the risk of leaving behind server-side resources.MongoClient.close() can be called concurrently
In the past, concurrent calls to
MongoClient.close()
had poorly defined behavior depending on the exact timing of the second (or more) calls to close(). In some cases, this could also throw errors.With these changes, MongoClient.close() can be called concurrently safely and always returns the same promise.
Note
This is intended as a correctness fix - we don't recommend calling MongoClient.close() concurrently if it can be avoided.
MONGODB-OIDC now properly reauthenticates in speculative auth scenarios
When using MONGODB-OIDC authentication, if the initial handshake contained speculative authentication, the driver would not properly reauthenticate when the server would raise 391 errors. This is now fixed.
Features
Bug Fixes
Performance Improvements
Documentation
We invite you to try the
mongodb
library immediately, and report any issues to the NODE project.6.12.0 (2024-12-10)
The MongoDB Node.js team is pleased to announce version 6.12.0 of the
mongodb
package!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.error
field 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
mongodb
library 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
mongodb
package!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,
timeoutMS
that 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
timeoutMS
as 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?
timeoutMS
The main new option introduced with CSOT is the
timeoutMS
option. 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
timeoutMS
option is specified, it will always take precedence over the following options:socketTimeoutMS
waitQueueTimeoutMS
wTimeoutMS
maxTimeMS
maxCommitTimeMS
Note, however that
timeoutMS
DOES NOT unconditionally override theserverSelectionTimeoutMS
option.When
timeoutMS
is 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 forserverSelectionTimeoutMS
of30000
.After server selection and connection checkout are complete, the time remaining bounds the execution of the remainder of the operation.
Note
Specifying
timeoutMS
is 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 * timeoutMS
in'cursorLifetimeMode'
and(n+1) * timeoutMS
when returning n batches in'iteration'
modeAbstractCursor.[Symbol.asyncIterator]()
- can take up to2 * timeoutMS
in'cursorLifetimeMode'
and (n+1)*timeoutMS
when 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.toArray
case 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 thekillCursors
command to close the cursor on the server.The
MongoClient.bulkWrite
and autoencryption implementations use cursors under the hood and so inherit this issue.Cursors,
timeoutMS
andtimeoutMode
Cursors 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 thetimeoutMS
to 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 subsequentgetMore
calls MUST finish withintimeoutMS
or 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 akillCursors
operation to the server.e.g.
The second,
'iteration'
mode, usestimeoutMS
to bound eachnext
/hasNext
/tryNext
call, 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
timeoutMode
is also configurable on a per-cursor basis.GridFS and
timeoutMS
GridFS streams interact with
timeoutMS
in a similar manner to cursors in'cursorLifeTime'
mode in thattimeoutMS
bounds the entire lifetime of the stream.In addition,
GridFSBucket.find
,GridFSBucket.rename
andGridFSBucket.drop
all support thetimeoutMS
option and behave in the same way as other operations.Sessions, Transactions,
timeoutMS
anddefaultTimeoutMS
ClientSessions have a new option:
defaultTimeoutMS
, which specifies thetimeoutMS
value to use for:commitTransaction
abortTransaction
withTransaction
endSession
Note
If
defaultTimeoutMS
is not specified, then it will inherit thetimeoutMS
of the parentMongoClient
.When using
ClientSession.withTransaction
, thetimeoutMS
can be configured either in the options on thewithTransaction
call or inherited from the session'sdefaultTimeoutMS
. ThistimeoutMS
will apply to the entirety of thewithTransaction
callback 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 thetimeoutMS
at the operation level for operations making use of the explicit session inside thewithTransaction
callback 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
timeoutMS
The
ClientEncryption
class now supports thetimeoutMS
option. IftimeoutMS
is provided when constructing aClientEncryption
instance, it will be used to govern the lifetime of all operations performed on instance, otherwise, it will inherit from thetimeoutMS
set on theMongoClient
provided to theClientEncryption
constructor.If
timeoutMS
is set on both the client and provided to ClientEncryption directly, the option provided toClientEncryption
takes 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
MongoClient
if 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
timeoutMS
Explain helpers support timeoutMS:
Note
Providing a
maxTimeMS
value with atimeoutMS
value 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
ENVIRONMENT
auth mechanism property in the URI orMongoClient
options 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,
ConnectionClosedEvent
s are now always emitted afterPoolClearEvent
s.Features
Bug Fixes
Performance Improvements
Documentation
We invite you to try the
mongodb
library 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
mongodb
package!Release Notes