The MongoDB Node.js team is pleased to announce version 4.10.0 of the mongodb package!
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:
awaitsyntax 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.
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-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:
- 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)
- 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)
- Reference: https://docs.mongodb.com/drivers/node/current/
- API: mongodb
- Changelog: node-mongodb-native/HISTORY.md at main · mongodb/node-mongodb-native · GitHub
We invite you to try the mongodb library immediately, and report any issues to the NODE project.