Releases: mongodb/node-mongodb-native
v6.3.0
6.3.0 (2023-11-15)
The MongoDB Node.js team is pleased to announce version 6.3.0 of the mongodb
package!
Release Notes
New client option serverMonitoringMode
For users that want to control the behaviour of the monitoring connection between each node in the topology, a new option, serverMonitoringMode
, has been added. This defaults to auto
but can be forced into a specific mode by providing a value of poll
or stream
. When the setting is auto
the monitoring mode will be determined by the environment the driver is running in, specifically, FaaS environments prefer "polling" mode and all others prefer "streaming".
A polling monitor periodically issues a hello
command to the node at an interval of heartbeatFrequencyMS
. A streaming monitor sends an initial hello
and then will automatically get a response from the Node when a change in server configuration occurs or at a maximum time of heartbeatFrequencyMS
. The value of that option defaults to 10000 milliseconds.
This new option can be provided in the connection string or as an option to the MongoClient
.
// In the connection string.
new MongoClient('mongodb://127.0.0.1:27017/?serverMonitoringMode=stream');
// In the options
new MongoClient('mongodb://127.0.0.1:27017/', { serverMonitoringMode: 'stream' });
Fix connection leak when serverApi
is enabled
When enabling serverApi
the driver's RTT measurement logic (used to determine the closest node) still sent the legacy hello command "isMaster" causing the server to return an error. Unfortunately, the error handling logic did not correctly destroy the socket which would cause a leak.
Both sending the correct hello command and the error handling connection clean-up logic are fixed in this change.
GridFS fields deprecated
The GridFS contentType
and aliases
options are deprecated. According to the GridFS spec, applications wishing to store contentType
and aliases
should add a corresponding field to the metadata
document instead.
Remove deprecation warning about punycode
The mongodb-connection-string-url
package which parses connection strings relied on Node's punycode module, the package now imports the community package removing the deprecation warning on Node.js 20+.
Features
- NODE-3881: require hello command + OP_MSG when 'loadBalanced=True' (#3907) (fd58eec)
- NODE-5197: add server monitoring mode (#3899) (ae4c94a)
- NODE-5590: deprecate GridFS fields (#3905) (d2225da)
Bug Fixes
- NODE-4863: do not use RetryableWriteError for non-server errors (#3914) (08c9fb4)
- NODE-5709: bump mongodb-connection-string-url to 3.0.0 (#3909) (1c3dc02)
- NODE-5749: RTTPinger always sends legacy hello (#3921) (ebbfb8a)
Documentation
We invite you to try the mongodb
library immediately and report any issues to the NODE project.
v6.2.0
6.2.0 (2023-10-19)
The MongoDB Node.js team is pleased to announce version 6.2.0 of the mongodb
package!
Release Notes
Updated to BSON 6.2.0
BSON now prints in full color! 🌈 🚀

See our release notes for BSON 6.2.0 here for more examples!
insertedIds
in bulk write now contain only successful insertions
Prior to this fix, the bulk write error's result.insertedIds
property contained the _id
of each attempted insert in a bulk operation.
Now, when a bulkwrite()
or an insertMany()
operation rejects one or more inserts, throwing an error, the error's result.insertedIds
property will only contain the _id
fields of successfully inserted documents.
Fixed edge case leak in findOne()
When running a findOne
against a time series collection, the driver left the implicit session for the cursor un-ended due to the way the server returns the resulting cursor information. Now the cursor will always be cleaned up regardless of the outcome of the find operation.
Removed client-side collection and database name validation
Database and collection name checking will now be in sync with the MongoDB server's naming restrictions. Specifically, users can now create collections that start or end with the '.' character.
Features
- NODE-5613: add
awaited
field to SDAM heartbeat events (#3895) (b50aadc) - update bson to 6.2.0 (#3898) (32b7176)
Bug Fixes
- NODE-5496: remove client-side collection and database name check validation (#3873) (98550c6)
- NODE-5628: bulkWriteResult.insertedIds does not filter out _ids that are not actually inserted (#3867) (09f2a67)
- NODE-5706: make findOne() close implicit session to avoid memory leak (#3897) (995d138)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v5.9.1
5.9.1 (2023-10-18)
The MongoDB Node.js team is pleased to announce version 5.9.1 of the mongodb
package!
Release Notes
insertedIds
in bulk write now contain only successful insertions
Prior to this fix, the bulk write error's result.insertedIds
property contained the _id
of each attempted insert in a bulk operation.
Now, when a bulkwrite()
or an insertMany()
operation rejects one or more inserts, throwing an error, the error's result.insertedIds
property will only contain the _id
fields of successfully inserted documents.
Fixed edge case leak in findOne()
When running a findOne
against a time series collection, the driver left the implicit session for the cursor un-ended due to the way the server returns the resulting cursor information. Now the cursor will always be cleaned up regardless of the outcome of the find operation.
Bug Fixes
- NODE-5627: BulkWriteResult.insertedIds includes ids that were not inserted (#3870) (d766ae2)
- NODE-5691: make findOne() close implicit session to avoid memory leak (#3889) (0d6c9cd)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v6.1.0
6.1.0 (2023-09-14)
The MongoDB Node.js team is pleased to announce version 6.1.0 of the mongodb
package!
Release Notes
Bump bson version to expose new Decimal128.fromStringWithRounding()
method
In this release, we have adopted the changes made to Decimal128 in bson version 6.1.0. We have added a new fromStringWithRounding()
method which exposes the previously available inexact rounding behaviour.
See the bson v6.1.0 release notes for more information.
Use region settings for STS AWS credentials request
When using IAM AssumeRoleWithWebIdentity AWS authentication the driver uses the @aws-sdk/credential-providers package to contact the Security Token Service API for temporary credentials. AWS recommends using Regional AWS STS endpoints instead of the global endpoint to reduce latency, build-in redundancy, and increase session token validity. Unfortunately, environment variables AWS_STS_REGIONAL_ENDPOINTS
and AWS_REGION
do not directly control the region the SDK's STS client contacts for credentials.
The driver now has added support for detecting these variables and setting the appropriate options when calling the SDK's API: fromNodeProviderChain().
Important
The driver will only set region options if BOTH environment variables are present. AWS_STS_REGIONAL_ENDPOINTS
MUST be set to either 'legacy'
or 'regional'
, and AWS_REGION
must be set.
Fix memory leak with ChangeStreams
In a previous release, 5.7.0, we refactored cursor internals from callbacks to async/await. In particular, the next
function that powers cursors was written with callbacks and would recursively call itself depending on the cursor type. For ChangeStreams
, this function would call itself if there were no new changes to return to the user. After converting that code to async/await each recursive call created a new promise that saved the current async context. This would slowly build up memory usage if no new changes came in to unwind the recursive calls.
The function is now implemented as a loop, memory leak be gone!
Features
Bug Fixes
- NODE-5551: set AWS region from environment variable for STSClient (#3831) (e9a5079)
- NODE-5588: recursive calls to next cause memory leak (#3841) (9a8fdb2)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v5.9.0
5.9.0 (2023-09-14)
The MongoDB Node.js team is pleased to announce version 5.9.0 of the mongodb
package!
Release Notes
Bumped bson
version to make use of new Decimal128
behaviour
In this release, we have adopted the changes made to Decimal128
in bson version 5.5. The Decimal128
constructor and fromString()
methods now throw when detecting a loss of precision (more than 34 significant digits). We also expose a new fromStringWithRounding()
method which restores the previous rounding behaviour.
See the bson v5.5.0 release notes for more information.
Use region settings for STS AWS credentials request
When using IAM AssumeRoleWithWebIdentity AWS authentication the driver uses the @aws-sdk/credential-providers package to contact the Security Token Service API for temporary credentials. AWS recommends using Regional AWS STS endpoints instead of the global endpoint to reduce latency, build-in redundancy, and increase session token validity. Unfortunately, environment variables AWS_STS_REGIONAL_ENDPOINTS
and AWS_REGION
do not directly control the region the SDK's STS client contacts for credentials.
The driver now has added support for detecting these variables and setting the appropriate options when calling the SDK's API: fromNodeProviderChain().
Important
The driver will only set region options if BOTH environment variables are present. AWS_STS_REGIONAL_ENDPOINTS
MUST be set to either 'legacy'
or 'regional'
, and AWS_REGION
must be set.
Fix memory leak with ChangeStreams
In a previous release, 5.7.0, we refactored cursor internals from callbacks to async/await. In particular, the next
function that powers cursors was written with callbacks and would recursively call itself depending on the cursor type. For ChangeStreams
, this function would call itself if there were no new changes to return to the user. After converting that code to async/await each recursive call created a new promise that saved the current async context. This would slowly build up memory usage if no new changes came in to unwind the recursive calls.
The function is now implemented as a loop, memory leak be gone!
Features
Bug Fixes
- NODE-5550: set AWS region from environment variable for STSClient (#3851) (2fab06b)
- NODE-5587: recursive calls to next cause memory leak (#3842) (f60f1b5)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v6.0.0
6.0.0 (2023-08-22)
The MongoDB Node.js team is pleased to announce version 6.0.0 of the mongodb
package!
The main focus of this release was usability improvements and a streamlined API. Read on for details!
Release Notes
Important
This is a list of changes relative to v5.8.1 of the driver. ALL changes listed below are BREAKING.
Users migrating from an older version of the driver are advised to upgrade to at least v5.8.1 before adopting v6.
🛠️ Runtime and dependency updates
Minimum Node.js version is now v16.20.1
The minimum supported Node.js version is now v16.20.1. We strive to keep our minimum supported Node.js version in sync with the runtime's release cadence to keep up with the latest security updates and modern language features.
BSON version 6.0.0
This driver version has been updated to use [email protected]
. BSON functionality re-exported from the driver is subject to the changes outlined in the BSON V6 release notes.
Optional peer dependency version bumps
kerberos
optional peer dependency minimum version raised to2.0.1
, dropped support for1.x
zstd
optional peer depedency minimum version raised to1.1.0
from1.0.0
mongodb-client-encryption
optional peer dependency minimum version raised to6.0.0
from2.3.0
(note thatmongodb-client-encryption
does not have3.x-5.x
version releases)
Note
As of version 6.0.0, all useful public APIs formerly exposed from mongodb-client-encryption
have been moved into the driver and should now be imported directly from the driver. These APIs rely internally on the functionality exposed from mongodb-client-encryption
, but there is no longer any need to explicitly reference mongodb-client-encryption
in your application code.
Allow socks
to be installed optionally
The driver uses the socks
dependency to connect to mongod
or mongos
through a SOCKS5 proxy. socks
used to be a required dependency of the driver and was installed automatically. Now, socks
is a peerDependency
that must be installed to enable socks
proxy support.
☀️ API usability improvements
findOneAndX
family of methods will now return only the found document or null
by default (includeResultMetadata
is false by default)
Previously, the default return type of this family of methods was a ModifyResult
containing the found document and additional metadata. This additional metadata is unnecessary for the majority of use cases, so now, by default, they will return only the found document or null
.
The previous behavior is still available by explicitly setting includeResultMetadata: true
in the options.
See the following blog post for more information.
// This has the same behaviour as providing `{ includeResultMetadata: false }` in the v5.7.0+ driver
await collection.findOneAndUpdate({ hello: 'world' }, { $set: { hello: 'WORLD' } });
// > { _id: new ObjectId("64c4204517f785be30795c92"), hello: 'world' }
// This has the same behaviour as providing no options in any previous version of the driver
await collection.findOneAndUpdate(
{ hello: 'world' },
{ $set: { hello: 'WORLD' } },
{ includeResultMetadata: true }
);
// > {
// > lastErrorObject: { n: 1, updatedExisting: true },
// > value: { _id: new ObjectId("64c4208b17f785be30795c93"), hello: 'world' },
// > ok: 1
// > }
session.commitTransaction()
and session.abortTransaction()
return void
Each of these methods erroneously returned server command results that can be different depending on server version or type the driver is connected to. These methods return a promise that if resolved means the command (aborting or commiting) sucessfully completed and rejects otherwise. Viewing command responses is possible through the command monitoring APIs on the MongoClient
.
withSession
and withTransaction
return the value returned by the provided function
The await client.withSession(async session => {})
now returns the value that the provided function returns. Previously, this function returned void
this is a feature to align with the following breaking change.
The await session.withTransaction(async () => {})
method now returns the value that the provided function returns. Previously, this function returned the server command response which is subject to change depending on the server version or type the driver is connected to. The return value got in the way of writing robust, reliable, consistent code no matter the backing database supporting the application.
Warning
When upgrading to this version of the driver, be sure to audit any usages of withTransaction
for if
statements or other conditional checks on the return value of withTransaction
. Previously, the return value was the command response if the transaction was committed and undefined
if it had been manually aborted. It would only throw if an operation or the author of the function threw an error. Since prior to this release it was not possible to get the result of the function passed to withTransaction
we suspect most existing functions passed to this method return void
, making withTransaction
a void
returning function in this major release. Take care to ensure that the return values of your function match the expectation of the code that follows the completion of withTransaction
.
Driver methods throw if a session is provided from a different MongoClient
Providing a session from one MongoClient
to a method on a different MongoClient
has never been a supported use case and leads to undefined behavior. To prevent this mistake, the driver now throws a MongoInvalidArgumentError
if session is provided to a driver helper from a different MongoClient
.
// pre v6
const session = client1.startSession();
client2.db('foo').collection('bar').insertOne({ name: 'john doe' }, { session }); // no error thrown, undefined behavior
// v6+
const session = client1.startSession();
client2.db('foo').collection('bar').insertOne({ name: 'john doe' }, { session });
// MongoInvalidArgumentError thrown
Callbacks removed from ClientEncryption's encrypt
, decrypt
, and createDataKey
methods
Driver v5 dropped support for callbacks in asynchronous functions in favor of returning promises in order to provide more consistent type and API experience. In alignment with that, we are now removing support for callbacks from the ClientEncryption
class.
MongoCryptError
is now a subclass of MongoError
Since MongoCryptError
made use of Node.js 16's Error
API, it has long supported setting the Error.cause
field using options passed in via the constructor. Now that Node.js 16 is our minimum supported version, MongoError
has been modified to make use of this API as well, allowing us to let MongoCryptError
subclass from it directly.
⚙️ Option parsing improvements
useNewUrlParser
and useUnifiedTopology
emit deprecation warnings
These options were removed in 4.0.0 but continued to be parsed and silently left unused. We have now added a deprecation warning through Node.js' warning system and will fully remove these options in the next major release.
Boolean options only accept 'true' or 'false' in connection strings
Prior to this change, we accepted the values '1', 'y', 'yes', 't'
as synonyms for true
and '-1', '0', 'f', 'n', 'no'
as synonyms for false
. These have now been removed in an effort to make working with connection string options simpler.
// Incorrect
const client = new MongoClient('mongodb://localhost:27017?tls=1'); // throws MongoParseError
// Correct
const client = new MongoClient('mongodb://localhost:27017?tls=true');
Repeated options are no longer allowed in connection strings
In order to avoid accidental misconfiguration the driver will no longer prioritize the first instance of an option provided on the URI. Instead repeated options that are not permitted to be repeated will throw an error.
This change will ensure that connection strings that contain options like tls=true&tls=false
are no longer ambiguous.
TLS certificate authority and certificate-key files are now read asynchronously
In order to align with Node.js best practices of keeping I/O async, we have updated the MongoClient
to store the file names provided to the existing tlsCAFile
and tlsCertificateKeyFile
options, as well as the tlsCRLFile
option, and only read these files the first time it connects. Prior to this change, the files were read synchronously on MongoClient
construction.
Note
This has no effect on driver functionality when TLS configuration files are properly specified. However, if there are any issues with the TLS configuration files (invalid file name), the error is now thrown when the MongoClient
is connected instead of at construction time.
const client = new MongoClient(CONNECTION_STRING, {
tls: true,
tlsCAFile: 'caFileName',
tlsCertificateKeyFile: 'certKeyFile',
tlsCRLFile: 'crlPemFile'
}); // Files are not read here, but file names are stored on the MongoClient
await client.connect(); // Files are now read and their contents stored
await client.close();
await client.connect(); // Since the file contents have already been cached, the files will not be read again.
Take a look at our [TLS documentation](https://www....
v5.8.1
5.8.1 (2023-08-23)
The MongoDB Node.js team is pleased to announce version 5.8.1 of the mongodb
package!
Release Notes
Import of saslprep
updated to correct library.
Fixes the import of saslprep to be the correct @mongodb-js/saslprep
library.
Bug Fixes
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v4.17.1
4.17.1 (2023-08-23)
The MongoDB Node.js team is pleased to announce version 4.17.1 of the mongodb
package!
Release Notes
Import of saslprep
updated to correct library.
Fixes the import of saslprep to be the correct @mongodb-js/saslprep
library.
Bug Fixes
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v5.8.0
5.8.0 (2023-08-21)
The MongoDB Node.js team is pleased to announce version 5.8.0 of the mongodb
package!
Release Notes
The AutoEncrypter
interface has been deprecated
The AutoEncrypter
interface was used internally but accidentally made public in the 4.x version of the driver. It is now deprecated and will be made internal in the next major release.
Kerberos support for 1.x and 2.x
Moves the kerberos dependency back to ^1.0.0 || ^2.0.0
to indicate support for both 1.x and 2.x. Support for 1.x is removed in 6.0.
Fixed accidental deprecation warning
Because of internal options handling, a deprecation was emitted for tlsCertificateFile
when using tlsCertificateKeyFile
. That has been corrected.
Remove credential availability on ConnectionPoolCreatedEvent
In order to avoid mistakenly printing credentials the ConnectionPoolCreatedEvent
will replace the credentials option with an empty object. The credentials are still accessble via MongoClient options: client.options.credentials
.
Features
- NODE-5399: use mongodb-js/saslprep instead of saslprep (#3818) (c0d3927)
- NODE-5429: deprecate the
AutoEncrypter
interface (#3764) (9bb0d95) - NODE-5465,NODE-5538: lower
@aws-sdk/credential-providers
version to 3.188.0 andzstd
to^1.0.0
(#3821) (39ff81d)
Bug Fixes
- NODE-5489: set kerberos compatibility to ^1.0.0 || ^2.0.0 (#3803) (c3b35b3)
- NODE-5495: do not emit deprecation warning when tlsCertificateKeyFile is specified and tlsCertificateFile is not (#3810) (e81d4a2)
- NODE-5537: remove credentials from ConnectionPoolCreatedEvent options (#3813) (4cf1e96)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v4.17.0
4.17.0 (2023-08-17)
The MongoDB Node.js team is pleased to announce version 4.17.0 of the mongodb
package!
Release Notes
mongodb-js/saslprep
is now installed by default
Until v6, the driver included the saslprep
package as an optional dependency for SCRAM-SHA-256 authentication. saslprep
breaks when bundled with webpack because it attempted to read a file relative to the package location and consequently the driver would throw errors when using SCRAM-SHA-256 if it were bundled.
The driver now depends on mongodb-js/saslprep
, a fork of saslprep
that can be bundled with webpack because it includes the necessary saslprep data in memory upon loading. This will be installed by default but will only be used if SCRAM-SHA-256 authentication is used.
Remove credential availability on ConnectionPoolCreatedEvent
In order to avoid mistakenly printing credentials the ConnectionPoolCreatedEvent
will replace the credentials option with an empty object. The credentials are still accessble via MongoClient options: client.options.credentials
.
Features
- NODE-5272: do not create or drop ecc collections (#3678) (d26ad61)
- NODE-5398: use mongodb-js/saslprep instead of saslprep (#3820) (5244711)
Bug Fixes
- NODE-5262: AWS Lambda metadata detection logic is too permissive (#3683) (c0c3d99)
- NODE-5311: construct error messages for AggregateErrors in Node16+ (#3683) (98b7bdf)
- NODE-5316: prevent parallel topology creation in MongoClient.connect (#3696) (e13038d)
- Thank you @clemclx for contributing this fix! 🎉
- NODE-5356: prevent scram auth from throwing TypeError if saslprep is not a function (#3732) (2d028af)
- NODE-5536: remove credentials from ConnectionPoolCreatedEvent options (#3812) (2910dca)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.