Releases: mongodb/node-mongodb-native
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 bson@6.0.0
. 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.
v5.7.0
5.7.0 (2023-07-06)
The MongoDB Node.js team is pleased to announce version 5.7.0 of the mongodb
package!
Release Notes
Write Concern legacy options deprecated
wtimeout
, j
, and fsync
options have been deprecated, please use wtimeoutMS
and journal
instead.
Legacy SSL options deprecated
In an effort to simplify TLS setup and use with the driver we're paring down the number of custom options to the ones that are common to all drivers. This should reduce inadvertent misconfiguration due to conflicting options.
The legacy "ssl-" options have been deprecated, each has a corresponding "tls-" option listed in the table below (except for sslCRL
, you may directly use the Node.js crl
option instead). tlsCertificateFile
has also been deprecated, please use tlsCertificateKeyFile
or pass the cert
directly to the MongoClient constructor.
In addition to the common driver options, the Node.js driver also passes through Node.js TLS options provided on the MongoClient to Node.js' tls.connect API, which may be convenient to reuse with other Node.js APIs.
Node.js native option | MongoDB driver option name | legacy option name | driver option type |
---|---|---|---|
ca |
tlsCAFile |
sslCA |
string |
crl |
N/A | sslCRL |
string |
cert |
tlsCertificateKeyFile |
sslCert |
string |
key |
tlsCertificateKeyFile |
sslKey |
string |
passphrase |
tlsCertificateKeyFilePassword |
sslPass |
string |
rejectUnauthorized |
tlsAllowInvalidCertificates |
sslValidate |
boolean |
New includeResultMetadata
option for findOneAnd...
family of methods.
This option defaults to true
, which will return a ModifyResult
type. When set to false
, which will
become the default in the next major release, it will return the modified document or null
if nothing matched.
This applies to findOneAndDelete
, findOneAndUpdate
, findOneAndReplace
.
// With a document { _id: 1, a: 1 } in the collection
await collection.findOneAndDelete({ a: 1 }, { includeResultMetadata: false }); // returns { _id: 1, a: 1 }
await collection.findOneAndDelete({ a: 2 }, { includeResultMetadata: false }); // returns null
await collection.findOneAndDelete({ a: 1 }, { includeResultMetadata: true }); // returns { ok: 1, lastErrorObject: { n: 1 }, value: { _id: 1, a: 1 }}
Support for change stream split events
When change stream documents exceed the max BSON size limit of 16MB, they can be split into multiple fragments in order to not error when sending events over the wire. In order to enable this functionality, the collection must be created with changeStreamPreAndPostImages
enabled and the change stream itself must include an $changeStreamSplitLargeEvent
aggregation stage. This feature requires a minimum server version of 7.0.0.
Example:
await db.createCollection('test', { changeStreamPreAndPostImages: { enabled: true }});
const collection = db.collection('test');
const changeStream = collection.watch([{ $changeStreamSplitLargeEvent: {} ], {
fullDocumentBeforeChange: 'required'
});
for await (const change of changeStream) {
console.log(change.splitEvent); // If changes over 16MB: { fragment: n, of: n }
}
Programmatic management of search indexes
This PR adds support for managing search indexes (creating, updating, deleting and listing indexes). The new methods are available on the Collection
class.
const indexes = await collection.listSearchIndexes().toArray(); // produces an array of search indexes
await collection.createSearchIndex({ name: 'my-index', definition: < index definition > } );
await collection.updateSearchIndex('my-index', < new definition >);
await collection.dropSearchIndex('my-index');
BSON updated to v5.4.0
Take a look at the bson
package's release notes!
Snappy loaded lazily
Unlike our other compression mechanisms snappy was loaded at the module level, meaning it would be optionally imported whether or not the driver was configured to use snappy compression. Snappy is now aligned with our other optional peer dependencies and is only loaded when enabled.
Zstd and Kerberos are now optional peer dependencies
This allows users who do not use these features to not have them installed. Users who do use these feature will now have them lazy loaded upon first use.
listDatabases
nameOnly
option bug fix
The listDatabases
API exposes the nameOnly
option which allows you to limit its output to only the names of the databases on a given mongoDB deployment:
db.admin().listDatabases({ nameOnly: true });
// [
// { name: 'local' },
// { name: 'movies' },
// ...
// ]
Prior to this fix, the option was not being set properly on the command, so the output was always given in full.
Thanks to @redixhumayun for submitting this fix!
saslprep
"is not a function" fix for bundled deployments
saslprep
is an optional dependency used to perform Stringprep Profile for User Names and Passwords for SCRAM-SHA-256 authentication. The saslprep
library breaks when it is bundled, causing the driver to throw TypeError
s.
This release includes a fix that prevents the driver throwing TypeError
s when attempting to use saslprep
in bundled environments.
Cursor.map transform bug fixes
The cursor API provides the ability to apply a map
function to each document in the cursor:
const cursor = collection.find({ name: 'john doe' }).map(({ name }) => name);
for await (const document of cursor) {
console.error(document); // only prints the `name` field from each document
}
Cursor iteration properly catches errors thrown from the transform applied in Cursor.map
Starting in version 4.0 of the driver, if the transform function throws an error, there are certain scenarios where the driver does not correctly catch this error and an uncaught exception is thrown:
const cursor = collection.find({ name: 'john doe' }).map(() => {
throw new Error('oh no! error here'); //
});
await cursor.next(); // process crashes with uncaught error
This release adds logic to ensure that whenever we transform a cursor document, we handle any errors properly. Any errors thrown from a transform function are caught and returned to the user.
Cursor.hasNext no longer transforms documents if a transform has been applied to the cursor
Version 4.0 introduced a bug that would apply a transform
function to documents in the cursor when the cursor was iterated using Cursor.hasNext()
. When combined with Cursor.next()
, this would result in transforming documents multiple times.
const cursor = collection.find({ name: 'john doe' }).map((document) => document.name);
while (await cursor.hasNext()) { // this transforms the first document in the cursor once
const doc = await cursor.next(); // the second document in the cursor is transformed again
}
This release removes the transform logic from Cursor.hasNext
, preventing cursor documents from being transformed twice when iterated using hasNext
.
Features
- NODE-5008: add zstd and kerberos to peer deps (#3691) (9561f32)
- NODE-5241: add option to return modified document (#3710) (d9c2600)
- NODE-5243: add change stream split event (#3745) (1c84f82)
- NODE-5274: deprecate write concern options (#3752) (1f880ea)
- NODE-5287: deprecate ssl options (#3743) (f9b5677)
- NODE-5319: mark search index api public (#3741) (c015e54)
- NODE-5407: update bson to 5.4.0 (#3754) (6a574cf)
Bug Fixes
- NODE-4977: load snappy lazily (#3726) ([865e658](865e658e7a341c8e9bd64...
v3.7.4
The MongoDB Node.js team is pleased to announce version 3.7.4 of the mongodb
package!
Release Highlights
This release fixes a bug that throws a type error when SCRAM-SHA-256 is used with saslprep in a webpacked environment.
3.7.4 (2023-06-21)
Bug Fixes
- NODE-3711: retry txn end on retryable write (#3047) (1595140)
- NODE-5355: prevent error when saslprep is not a function (#3733) (152425a)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v5.6.0
The MongoDB Node.js team is pleased to announce version 5.6.0 of the mongodb
package!
Release Highlights
Node 20 support
The MongoDB Node.js Driver now supports Node.js 20! 🎉
runCursorCommand
API
We have added the Db#runCursorCommand
method which can be used to execute generic cursor commands. This API complements the generic Db#command
method.
TypeScript support for new time series options
The driver now has TypeScript support for the bucketMaxSpanSeconds
and bucketRoundingSeconds
options which will be available in MongoDB 7.0. You can read more about these options here.
Features
- NODE-5019: add runCursorCommand API (#3655) (4da926e)
- NODE-5071: support additional time series options (#3667) (ccf555d)
Bug Fixes
- NODE-5249: remove strict flag from create collection options (#3677) (be8faaf)
- NODE-5296: construct error messages for AggregateErrors in Node16+ (#3682) (e03178e)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v5.5.0
The MongoDB Node.js team is pleased to announce version 5.5.0 of the mongodb
package!
Features
- NODE-4720: Add log messages to CMAP spec (#3645) (b27f385)
- NODE-5004: dont create or drop ecc collections (#3660) (2264fbb)
Bug Fixes
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
v5.4.0
The MongoDB Node.js team is pleased to announce version 5.4.0 of the mongodb
package!
Release Highlights
ChangeStream.tryNext
Typescript fix
We have corrected the tryNext method on ChangeStream to use the TChange
schema generic instead of the untyped Document
interface. This may increase strictness for existing usages but aligns with the rest of the methods on the change stream class to accurately reflect the type returned from the driver.
Deprecations
The db.command()
API has a number of options deprecated that were incorrectly included in the typescript interface the method reportedly accepts. A majority of the options relate to fields that must be attached to the command directly: readConcern
, writeConcern
, and comment
.
Additionally, the collStats helper has been deprecated in favor of using database aggregations to get the same result: https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/
NOTE: This release includes some experimental features that are not yet ready for production use. As a reminder, anything marked experimental is not a part of the stable driver API and is subject to change without notice.
Features and Deprecations
- NODE-5166: bump max wire version for 7.0 (#3659) (561229b)
- NODE-4970: deprecate collStats collection helper (#3638) (325c4bc)
- NODE-5207: deprecate unsupported runCommand options and add spec tests (#3643) (d6d76b4)
Bug Fixes
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.