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!
env MONGODB_LOG_ALL=debug node server.mjs
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.
๐ 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 and CommandSucceededEvent
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 its close()
-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
- NODE-5672: support standardized logging (#4387) (d1b2453)
- NODE-6258: add signal support to find and aggregate (#4364) (73def18)
- NODE-6451: retry SRV and TXT lookup for DNS timeout errors (#4375) (fd902d3)
- NODE-6633: MongoClient.close closes active cursors (#4372) (654069f)
Bug Fixes
- NODE-5225: concurrent MongoClient.close() calls each attempt to close the client (#4376) (9419af7)
- NODE-6340: OIDC reauth uses caches speculative auth result (#4379) (8b2b7fd)
Performance Improvements
- NODE-6452: Optimize CommandStartedEvent and CommandSucceededEvent constructors (#4371) (41b066b)
- NODE-6616: shortcircuit logging ejson.stringify (#4377) (c1bcf0d)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.