Releases: mongodb/node-mongodb-native
v4.1.4
Release Highlights
This release includes a couple of bug fixes as noted below:
Bug Fixes
- NODE-3515: do proper opTime merging in bulk results (#3012) (43300c3)
- NODE-3668: compile error with OptionalId on TS 4.5 beta (#3004) (ee7f095)
Documentation
- Reference: https://docs.mongodb.com/drivers/node
- API: https://mongodb.github.io/node-mongodb-native/4.1
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/4.1/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v3.7.3
The MongoDB Node.js team is pleased to announce version 3.7.3 of the mongodb package!
What's Changed
Full Changelog: v3.7.2...v3.7.3
Documentation
- Reference: https://docs.mongodb.com/drivers/node
- API: https://mongodb.github.io/node-mongodb-native/3.7
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/3.7/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v4.1.3
The MongoDB Node.js team is pleased to announce version 4.1.3 of the mongodb package!
Release Highlights
This release includes a couple of TypeScript fixes as noted below:
Bug Fixes
- NODE-3609: correct listDatabases return type (#2986) (a8e9938)
- NODE-3624: Incorrect default aggregation generic type (#2987) (440517e)
Documentation
- Reference: https://docs.mongodb.com/drivers/node
- API: https://mongodb.github.io/node-mongodb-native/4.1
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/4.1/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v3.7.2
The MongoDB Node.js team is pleased to announce version 3.7.2 of the mongodb package!
Release Highlights
This release contains a fix for optional require of dependencies on yarn berry.
Bug Fixes
Documentation
- Reference: https://docs.mongodb.com/drivers/node
- API: https://mongodb.github.io/node-mongodb-native/3.7
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/3.7/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v4.1.2
The MongoDB Node.js team is pleased to announce version 4.1.2 of the mongodb package!
Release Highlights
This release addresses a number of bug fixes, please peruse the list below for more information on each fix.
Bug Fixes
- NODE-3434: errInfo should be exposed on bulk write (#2977) (6b3c161)
- NODE-3467: allow object type for aggregate out helper (#2971) (cd603e8)
- NODE-3487: check for nullish aws mechanism property (#2951) (78ec0dd)
- NODE-3559: incorrect GridFS stream type (#2981) (3915ea8)
- NODE-3567: correct typing on aggregation out helper (#2967) (a299a0b)
- NODE-3574: reintroduce ObjectID export (#2965) (2291119)
- NODE-3585: MongoClientOptions#compressors has incorrect type (#2976) (f1b896d)
- NODE-3591: tlsCertificateKeyFile option does not default cert (#2979) (6d42267)
- NODE-3599: incorrect indexes return type (#2980) (122b9f3)
Documentation
- Reference: https://docs.mongodb.com/drivers/node
- API: https://mongodb.github.io/node-mongodb-native/4.1
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/4.1/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v3.7.1
The MongoDB Node.js team is pleased to announce version 3.7.1 of the mongodb package!
Release Highlights
This release contains an internal improvement that makes our monitor utilize the new hello handshake for monitoring when available.
Features
Documentation
- Reference: https://docs.mongodb.com/drivers/node
- API: https://mongodb.github.io/node-mongodb-native/3.7
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/3.7/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v3.7.0
The MongoDB Node.js team is pleased to announce version 3.7.0 of the mongodb package!
Release Highlights
Versioned API
Versioned API is a new feature in MongoDB 5.0 that allows user-selectable API versions, subsets of MongoDB server semantics, to be declared on a client. During communication with a server, clients with a declared API version will force the server to behave in a manner compatible with the API version. Declaring an API version on a client can be used to ensure consistent responses from a server, providing long term API stability for an application. The declared API version is applied to all commands run through the client, including those sent through the generic RunCommand helper. Specifying versioned API options in the command document AND declaring an API version on the client is not supported and will lead to undefined behavior.
Declare an API version on a client
// Declare API version "1" for the client
client = new MongoClient(uri, { serverApi: { version: '1' } });
cursor = client.db('database').collection('coll').find(...);
Strict mode
Declaring a strict
API version will cause the MongoDB server to reject all commands that are not part of the declared API version. This includes command options and aggregation pipeline stages. For example, the following find
call would fail because the tailable
option is not part of version 1:
// Declare API version "1" for the client, with strict on
client = new MongoClient(uri, { serverApi: { version: '1', strict: true } });
// Fails with an error
cursor = client.db('database').collection('coll').find({ ... }, { tailable: true });
Deprecation Errors
The deprecationErrors
option can be used to enable command failures when using functionality that is deprecated from version 1. Note that at the time of this writing, no deprecations in version 1 exist.
// Declare API version "1" for the client, with deprecationErrors on
client = new MongoClient(uri, { serverApi: { version: '1', deprecationErrors: true } });
// Note: since API version "1" is the initial version, there are no deprecated commands to provide as an example yet.
Features
Bug Fixes
- NODE-3377: driver should allow arbitrary explain levels (#2961) (96c8ab4)
- NODE-3463: pass explain error through to callback (#2949) (e5975af)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/3.7/api/
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/v3.7.0/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v3.6.12
The MongoDB Node.js team is pleased to announce version 3.6.12 of the mongodb package!
Bug Fixes
- NODE-3487: check for nullish aws mechanism property (#2957) (5902b4c)
- NODE-3528: add support for snappy v7 (#2947) (54f5c2d)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: https://mongodb.github.io/node-mongodb-native/3.6/api/
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/v3.6.12/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v4.1.1
The MongoDB Node.js team is pleased to announce version 4.1.1 of the mongodb package!
Release Highlights
Error handling
We introduced better organization and consistency to our existing errors in an effort to provide more detailed error types that can help identify issues clearly and quickly. Our readme has a new section that describes how to handle errors thrown by the driver and defines our approach to semver in the context of errors. Notably, we recommend only using instanceof
checks to filter for a given error class as we do not guarantee error messages or names will be preserved between patch releases, only the subclass hierarchy.
Thanks so much to our summer interns @andymina and @W-A-James for undertaking this effort!
Notable fixes
- This version of the driver brings in the latest BSON release which includes deserialization performance improvements.
- The snappy package recently released a major version bump (v7) that makes use of a rust implementation of Snappy compression. Our driver can now make use of this version (while maintaining compatibility with the previous v6).
findOne()
once again correctly returnsnull
when no match is found instead ofundefined
. This change was unintentional and not consistent with our other APIs. It slipped through testing due to the nature ofundefined
andnull
being nearly (==
) but not actually (===
) equal. We apologize if this results in the need for any code changes.
This release also addresses some Typescript issues that require further explanation, let's dive in:
TypeScript support
Projections
Starting in MongoDB 4.4 projections can accept aggregation expressions and aggregation syntax.
This empowers users to create some pretty amazing and complex data model transformations on the database side.
Unfortunately, our initial release of typescript typing for projections was too narrow to allow these use cases and still pass the compiler checks.
Now projections are generic objects and the result of a cursor with a projection is typed as a generic object by default.
The recommended usage for projections alongside typescript is as follows:
interface Pet {
name: string;
buddies: Pet[];
}
interface PetBuddyCount {
name: string;
buddyCount: number;
}
const pets = db.collection<Pet>('pets');
const petBuddyCounts = await pets.find().project<PetBuddyCount>({
name: 1,
buddyCount: { $size: '$buddies' },
}).toArray();
By using a parameterized .project
call you can now get the correct type information on the petBuddyCounts
array.
You will need to build the projection type yourself based on the projection you define for your query, but this has the benefit of constraining your results to precisely your type expectations.
Generics in find/findOne
In our initial typescript release the find
and findOne
methods accepted a generic parameter that was passed to the filter argument of the API.
find<T>(f: Filter<T>): FindCursor<T>
Due to how typescript automatically resolves the types of generics, one could run into an issue when specifying a filter that was incorrectly typed.
The code below should be a Typescript error, TS hints to us the name
is a string
so it should only allow an array of string
for $in
.
// (using the same pets collection from the last example)
pets.find({ name: { $in: [1, 2] } });
// instead of the expected FindCursor<Pet> type TS was resolving to:
const res: FindCursor<{name: {$in: number[]}}> = pets.find(/* same arg as above */);
It uses the incorrectly typed filter that does not match the schema of Filter<TSchema>
to automatically resolve a crazy return type.
The function definition has now been updated to be:
find<T>(f: Filter<TSchema>): FindCursor<T>
So the Filter argument will no longer be automatically resolved to the passed in type, giving us the typescript compiler errors we love so much!
Bug Fixes
- NODE-3454: projection types are too narrow (#2924) (48d6da9)
- NODE-3468: remove generic overrides from find (#2935) (74bd7bd)
- NODE-3511: deprecate fullResponse and remove associated buggy code paths (#2943) (dfc39d1)
- NODE-3528: add support for snappy 7 (#2939) (0f7f300)
- NODE-3546: revert findOne not found result type to null (#2945) (1c576e9)
Refactoring
- NODE-3404 implement MongoRuntimeError children (#2912) (e69d99257)
- NODE-3405 implement MongoRuntimeError children (#2913) (e69d99257)
Documentation
- Reference: https://docs.mongodb.com/drivers/node
- API: https://mongodb.github.io/node-mongodb-native/4.0
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/4.1/HISTORY.md
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
v3.6.11
The MongoDB Node.js team is pleased to announce version 3.6.11 of the mongodb package!
Release Highlights
This patch addresses a few bugs listed below.
Notably, we fixed an issue with the way we imported one of our optional dependencies that blocked webpack bundling.
If you are a webpack user you will still get warnings for our optional dependencies (if you don't use them).
You can hush the warnings by adding this option to your webpack config:
{
// ...
externals: [
'mongodb-client-encryption',
'aws4',
'saslprep',
'kerberos',
'snappy',
'bson-ext',
],
// ...
}
It is important to note that this will leave the imports in place and not pull in the code to your bundle. If you later do adopt using these dependencies you'll want to revert the relevant setting.
Bug Fixes
- NODE-1843: bulk operations ignoring provided sessions (#2898) (9244b17)
- NODE-3199: unable to bundle driver due to uncaught require (#2903) (60efe9d)
Documentation
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: http://mongodb.github.io/node-mongodb-native/3.6/api
- Changelog: https://github.com/mongodb/node-mongodb-native/blob/3.6/HISTORY.md
We invite you to try the mongodb package immediately, and report any issues to the NODE project.