Releases: mongodb/node-mongodb-native
v5.1.0
The MongoDB Node.js team is pleased to announce version 5.1.0 of the mongodb
package!
Release Highlights
Support for JavaScript bigint
s in the driver
The driver now supports automatic serialization of JavaScript bigint
s to BSON.Long
s. It also supports deserializing of BSON.Long
values returned from the server to bigint
values when the useBigInt64
flag is passed as true.
import { MongoClient } from 'mongodb';
(async () => {
const client = new MongoClient('<YOUR CONNECTION STRING>');
const db = client.db('test');
const coll = db.collection('bigints');
await coll.insertOne({ a: 10n }); // The driver automatically serializes bigints to BSON.Long before being sent to the server
const docBigInt = await coll.findOne({ a: 10n }, { useBigInt64: true }); // Must provide the useBigInt64 flag to specify that bigints get returned
console.log(docBigInt);
// { _id: ObjectId(...), a: 10n }
const doc = await coll.findOne({ a: 10n }); // Must provide the useBigInt64 flag to specify that bigints get returned
console.log(doc);
// { _id: ObjectId(...), a: 10 }
await client.close();
})()
Features
- NODE-3445: add support for AssumeRoleWithWebIdentity in aws authentication (#3556) (e8a30b1)
- NODE-4877: Add support for useBigInt64 (#3519) (917668c)
- NODE-5050: support GCP automatic credential fetch for CSFLE (#3574) (722a4a6)
Bug Fixes
- NODE-5044: Write Concern 0 Must Not Affect Read Operations (#3541) (#3575) (10146a4)
- NODE-5052: prevent cursor and changestream close logic from running more than once (#3562) (71d0d79)
- NODE-5064: consolidate connection cleanup logic and ensure socket is always closed (#3572) (e544d88)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/5.1/
- Changelog: HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v5.0.1
The MongoDB Node.js team is pleased to announce version 5.0.1 of the mongodb package!
This release reverts a fix that unintentionally caused a leak of internal driver resources.
Bug Fixes
- NODE-5027: revert "ensure that MessageStream is destroyed when connections are destroyed" (#3552) (2d178d0)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/5.0/
- Changelog: HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v4.14.0
The MongoDB Node.js team is pleased to announce version 4.14.0 of the mongodb package!
Deprecations
Bug Fixes
- NODE-4999: Write Concern 0 Must Not Affect Read Operations (#3541) (ddfc2b9)
- NODE-5026: revert "ensure that MessageStream is destroyed when connections are destroyed" (#3551) (c4da623)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/4.14/
- Changelog: HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v5.0.0
The MongoDB Node.js team is pleased to announce version 5.0.0 of the mongodb
package!
Release Highlights
Node.js driver v5 emphazises the modernization of our API.
Farewell to Callbacks
Most notably, we have removed support for callbacks in favor of a Promise-only public API.
To ease the migration to a Promise-only approach when using the Node.js driver, callback support is available via the mongodb-legacy
package. You can read more about this change in the Optional callback support migrated to mongodb-legacy
section of the migration guide.
Dot Notation No Longer Enabled by Default
Version 4.3.0 of the Node.js driver introduced strict type checking on Filter
queries that used dot notation. This functionality was enabled by default and proved to be a barrier for users upgrading to later versions of the Node.js v4.x driver. In order to ease the migration to v5.0.0, type strictness on queries that use dot notation has been removed from the CRUD API. The type checking capabilities are still available in an experimental type called StrictFilter
. You can read more about this change in the Dot Notation TypeScript Support Removed By Default section of the migration guide.
BSON v5
This release also adopts all the changes in BSON v5.0.0 (see the release notes).
The driver now exports a BSON
namespace that also has BSON.EJSON
APIs available.
When working in projects where both the driver and bson
are used, we recommend importing BSON types (ObjectId
, Long
, etc.) and BSON APIs from the driver instead of from BSON directly to ensure consistency when serializing and deserializing instances of the BSON types.
Other Notable Changes
@aws-sdk/credential-providers
has now been moved to an optional peer dependency.
Consequently, in v5.0.0 or later versions of the driver, the AWS credential provider module must be installed manually to enable the use of the native AWS SDK for authentication.
Collection.insert
, Collection.update
, and Collection.remove
methods have been removed in favor of their non-deprecated counterparts. You can read more about this and other changes in our Driver v5 Migration Guide.
⚠BREAKING CHANGES
- NODE-4522: remove callback support (#3499)
- NODE-4817: remove legacy logger (#3518)
- NODE-4867: adopt BSON v5 (#3490)
- NODE-4738: remove dot notation support by default (#3520)
- NODE-4950: remove bson-ext import (#3523)
- NODE-4756: ok 1 with write concern failure event changes (#3525)
- NODE-4034: make internal bulk result private (#3515)
- NODE-4751: drop support for client encryption < 2.3.0 (#3521)
- NODE-4684: remove collection insert, update, remove methods (#3500)
- NODE-4924: remove mapReduce collection helper (#3511)
- NODE-4925: remove deprecated options and types (#3513)
- NODE-3818: remove slaveOk options (#3503)
- NODE-3695: remove lastop and optime from bulk result (#3504)
- NODE-3489: remove cursor close options (#3505)
- NODE-4598: close cursor on early loop break (#3502)
- NODE-3482: remove unref (#3494)
- NODE-4521: remove custom promise library support (#3498)
- NODE-4898: aws credential providers now optional peerDependency (#3497)
- NODE-4436: update minimum supported node version (#3496)
- NODE-4899: support only snappy 7 or later (#3491)
Features
- NODE-5016: compile ts with target es2020 (#3545) (def266a)
- NODE-3482: remove unref (#3494) (556812f)
- NODE-3489: remove cursor close options (#3505) (88c03a1)
- NODE-3695: remove lastop and optime from bulk result (#3504) (8900d40)
- NODE-3818: remove slaveOk options (#3503) (2e28009)
- NODE-4034: make internal bulk result private (#3515) (ebac1f5)
- NODE-4436: update minimum supported node version (#3496) (cca5362)
- NODE-4509: send 1 with hello commands (#3508) (cc8ea1d)
- NODE-4521: remove custom promise library support (#3498) (af36ebb)
- NODE-4522: remove callback support (#3499) (52853ff)
- NODE-4598: close cursor on early loop break (#3502) (30c0aee)
- NODE-4684: remove collection insert, update, remove methods (#3500) (14427d1)
- NODE-4738: remove dot notation support by default (#3520) (26145df)
- NODE-4751: drop support for client encryption < 2.3.0 (#3521) (3dae6da)
- NODE-4756: ok 1 with write concern failure event changes (#3525) (fee783c)
- NODE-4767: Change abstract cursor return type (#3531) (410ef30)
- NODE-4817: remove legacy logger (#3518) (28c7cdd)
- NODE-4867: adopt BSON v5 (#3490) (b850868)
- NODE-4898: aws credential providers now optional peerDependency (#3497) (b9e4c7c)
- NODE-4899: support only snappy 7 or later (#3491) (21db1a9)
- NODE-4924: remove mapReduce collection helper (#3511) (10d757a)
- NODE-4925: remove deprecated options and types (#3513) (8f8ea45)
- NODE-4950: remove bson-ext import (#3523) (1470115)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/5.0/
- Changelog: HISTORY.md
We invite you to try the mongodb
library and report any issues to the NODE project.
v5.0.0-alpha.0
🚧 Testing Build Only
This alpha build is intended for internal testing only. Adopt at your own risk.
Changes listed in HISTORY.md.
5.0.0-alpha.0 diff v4.13.0 (2023-01-23)
v4.13.0
The MongoDB Node.js team is pleased to announce version 4.13.0 of the mongodb package!
Features
Bug Fixes
- NODE-4447: disable causal consistency in implicit sessions (#3479) (6566fb5)
- NODE-4834: ensure that MessageStream is destroyed when connections are destroyed (#3482) (8338bae)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/4.13/
- Changelog: HISTORY.md
We invite you to try the mongodb driver immediately, and report any issues to the NODE project.
v4.12.1
The MongoDB Node.js team is pleased to announce version 4.12.1 of the mongodb package!
Release Highlights
This version includes a fix to a regression in our monitoring logic that could cause process crashing errors that was introduced in v4.12.0.
If you are using v4.12.0 of the Node driver, we strongly encourage you to upgrade.
Bug Fixes
- NODE-4830: lazily import aws module (#3476) (ff375e9)
- NODE-4831: check map value is not undefined (#3477) (9795cdb)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
4.12.0
The MongoDB Node.js team is pleased to announce version 4.12.0 of the mongodb package!
Release Highlights
ChangeStreams are now AsyncIterators
ChangeStreams are now async iterables and can be used anywhere that expects an async iterable. Notably, change streams can now be used in Javascript for-await loops:
const changeStream = collection.watch();
for await (const change of changeStream) {
console.log(“Received change: “, change);
}
Some users may have been using change streams in for-await loops manually by using a for-await loop with the ChangeStream’s internal cursor. For example:
const changeStream = collection.watch();
for await (const change of changeStream.cursor) {
console.log(“Received change: “, change);
}
The change stream cursor has no support for resumabilty and consequently the change stream will never attempt to resume on any errors. We strongly caution against using a change stream cursor as an async iterable and strongly recommend using the change stream directly.
Server Monitoring Fix When Monitoring Events are Skipped
Version 4.7.0 of the Node driver released an improvement to our server monitoring in FAAS environments by allowing the driver to skip monitoring events if there were more than one monitoring events in the queue when the monitoring code restarted. When skipping monitoring events that contained a topology change, the driver would incorrectly fail to update its view of the topology.
Version 4.12.0 fixes this issue by ensuring that the topology is always updated when monitoring events are processed.
Performance Improvements with Buffering
This release also modifies the data structures used internally in the driver to use linked lists in places where random access is not required and constant time insertion and deletion is beneficial.
External Contributions
Many thanks to @ImRodry for helping us fix the documentation for our deprecated callback overloads in this release!
Features
Deprecations
- NODE-4681: deprecate modify result (#3459) (6a8776c)
- NODE-4733: deprecate result and getLastOp (#3458) (a143d3b)
- NODE-4757: deprecate unused PipeOptions (#3466) (1a5e619)
- NODE-4809: deprecate the existing logger (#3464) (1eea4f0)
Bug Fixes
- NODE-4609: allow mapping to falsey non-null values in cursors (#3452) (1bf6ef1)
- NODE-4735: fix change stream consecutive resumabilty (#3453) (89b27e9)
- NODE-4753: remove erroneous deprecation of geoNear (#3465) (199dcaf)
- NODE-4783: handle orphaned operation descriptions (#3463) (4c9b4d8)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.
4.11.0
The MongoDB Node.js team is pleased to announce version 4.11.0 of the mongodb package!
Release Highlights
Recursive Schema Support
Version 4.3.0 of the Node driver added Typescript support for dot notation into our Filter
type but
in the process it broke support for recursive schemas. In 4.11.0, we now support mutually recursive schemas and
provide type safety on dot notation queries up to a depth of 8. Beyond a depth of 8, code still compiles
but is no longer type checked (it falls back to a type of any
).
interface Author {
name: string;
bestBook: Book;
}
interface Book {
title: string;
author: Author;
}
let authors: Collection<Author>
// below a depth of 8, type checking is enforced
authors.findOne({ 'bestBook.author.bestBook.title': 25 }})
// ✅ expected compilation error is thrown: "title must be a string"
// at a depth greater than 8 code compiles but is not type checked (9 deep in this example)
authors.findOne({ 'bestBook.author.bestBook.author.bestBook.author.bestBook.author.name': 25 })
// ⛔️ perhaps unexpected, no compilation error is thrown because the key is too deeply nested
Note that our depth limit is a product of Typescript's recursive type limitations.
AWS Authentication
If the optional aws-sdk dependency is installed, the driver will now use the SDK to get credentials
from the environment. Because of this, if you have a shared AWS credentials or config file, then
those credentials will be used by default if AWS auth environment variables are not set. To override this
behavior, set AWS_SHARED_CREDENTIALS_FILE=""
in your shell or set the
equivalent environment variable value in your script or application. Alternatively, you can create
an AWS profile specifically for your MongoDB credentials and set the AWS_PROFILE
environment
variable to that profile name.
External Contributions
Many thanks to those who contributed to this release!
- @ermik provided an extremely large schema to test compilation with, which made testing our new recursive schema support possible with large schemas straightforward.
- @noahsilas for documentation improvements in change streams and fixing our Typescript types for read preferences.
- @zendagin for adding Typescript support for hashed indexes.
- @biniona-mongodb for fixing our parsing of TLS options.
- @LinusU for removing support for server versions lower than our minimum supported server version and improving error messages for unacknowledged writes with hints.
Features
- NODE-3651: add hashed index type (#3432) (f6b56a1)
- NODE-3875: support recursive schema types (#3433) (26bce4a)
- NODE-4503: throw original error when server attaches NoWritesPerformed label (#3441) (a7dab96)
- NODE-4650: handle handshake errors with SDAM (#3426) (cbe7533)
- NODE-4721: add aws-sdk as optional dependency (#3446) (b879cb5)
Bug Fixes
- NODE-3712,NODE-4546: electionId should be ordered before setVersion (#3174) (ca51fec)
- NODE-3921: error on invalid TLS option combinations (#3405) (1a550df)
- NODE-4186: accept ReadPreferenceLike in TransactionOptions type (#3425) (dc62bcb)
- NODE-4475: make interrupted message more specific (#3437) (5f37cb6)
- NODE-4608: prevent parallel monitor checks (#3404) (78bcfe4)
- NODE-4647: improve error message (#3409) (0d3c02e)
- NODE-4649: use SDAM handling for errors from min pool size population (#3424) (ef3b55d)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/4.11
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/main/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v4.10.0
The MongoDB Node.js team is pleased to announce version 4.10.0 of the mongodb package!
Release Highlights
Callback Deprecation
Looking to improve our API's consistency and handling of errors we are planning to remove callback support in the next major release of the driver. Today marks the notice of their removal. Migrating to a promise only API allows us to offer uniform error handling and better native support for automatic promise construction. In this release you will notice deprecation warnings in doc comments for all our callback overloads and if you are working in VSCode you should notice strikethroughs on these APIs. We encourage you to migrate to promises where possible:
- Using
async
/await
syntax can yield the best experience with promise usage. - Using Node.js' callbackify utility is one approach:
require('util').callbackify(() => collection.findOne())(callback)
- Using .then syntax is another:
collection.findOne().then(res => callback(null, res), err => callback(err))
- And lastly, for large codebases still intertwined with callbacks we have an alternative package prepared.
MongoDB-Legacy Callback Support
While the 4.10.0 version only deprecates our support of callbacks, there will be a major version that removes the support altogether. In order to keep using callbacks after v5 is released, we recommend migrating your driver version to mongodb-legacy (github link). This package wraps every single async API our driver offers and is designed to provide the exact behavior of the MongoDB 4.10.0 release (both callbacks and promises are supported). Any new features added to MongoDB will be automatically inherited but will only support promises. This package is fully tested against our current suite and adoption should be confined to changing an import require('mongodb')
-> require('mongodb-legacy')
. If this package is useful to you and your use case we encourage you to adopt it before v5 to ensure it continues to work as expected.
Read more about it on the package's readme here:
Features
- NODE-4385: add cmap pool pausing functionality (#3321) (335ee55)
- NODE-4484: add experimental support for disambiguatedPaths in change stream documents (#3365) (846365a)
- NODE-4519: deprecate promiseLibrary and PromiseProvider (#3403) (5c322b6)
- NODE-4547: mark all callback APIs as deprecated (#3388) (a983f14)
- NODE-4634: add support for bulk FindOperators.hint() (#3408) (8758890)
Bug Fixes
- NODE-3144: pool clear event ordering and retryability tests (#3407) (bdc0d67)
- NODE-4557: randomize servers when there are only 2 eligible servers (#3390) (ddcfa49)
- NODE-4583: revert nested union type support (#3383) (7f94f0a)
- NODE-4591: only set loadBalanced on handshake when explicitly set (#3386) (57e9f2d)
- NODE-4621: ipv6 address handling in HostAddress (#3410) (5eb3978)
- NODE-4639: allow PromiseProvider to be null (#3412) (d29b3d9)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/4.10
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/main/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.