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.