NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm, #3169 most downloaded on npm
The official MongoDB driver for Node.js
Latest stable
7.8.0
Last release 2 days ago
11 Nov 2026
Ships on a steady schedule
a new release about every 8 days
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
15 years old
962 releases · first in 2011
Drag across the ruler to compare, or tap a release to open it.
The MongoDB Node.js team is pleased to announce version 5.9.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 5.9.1 of the mongodb package!
insertedIds in bulk write now contain only successful insertionsPrior to this fix, the bulk write error's result.insertedIds property contained the _id of each attempted insert in a bulk operation.
Now, when a bulkwrite() or an insertMany() operation rejects one or more inserts, throwing an error, the error's result.insertedIds property will only contain the _id fields of successfully inserted documents.
findOne()When running a findOne against a time series collection, the driver left the implicit session for the cursor un-ended due to the way the server returns the resulting cursor information. Now the cursor will always be cleaned up regardless of the outcome of the find operation.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Your coding agent can read these notes before it upgrades. Set up the MCP server →
The MongoDB Node.js team is pleased to announce version 5.9.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 5.9.0 of the mongodb package!
bson version to make use of new Decimal128 behaviourIn this release, we have adopted the changes made to Decimal128 in bson version 5.5. The Decimal128 constructor and fromString() methods now throw when detecting a loss of precision (more than 34 significant digits). We also expose a new fromStringWithRounding() method which restores the previous rounding behaviour.
See the bson v5.5.0 release notes for more information.
When using IAM AssumeRoleWithWebIdentity AWS authentication the driver uses the @aws-sdk/credential-providers package to contact the Security Token Service API for temporary credentials. AWS recommends using Regional AWS STS endpoints instead of the global endpoint to reduce latency, build-in redundancy, and increase session token validity. Unfortunately, environment variables AWS_STS_REGIONAL_ENDPOINTS and AWS_REGION do not directly control the region the SDK's STS client contacts for credentials.
The driver now has added support for detecting these variables and setting the appropriate options when calling the SDK's API: fromNodeProviderChain().
[!IMPORTANT] The driver will only set region options if BOTH environment variables are present.
AWS_STS_REGIONAL_ENDPOINTSMUST be set to either'legacy'or'regional', andAWS_REGIONmust be set.
In a previous release, 5.7.0, we refactored cursor internals from callbacks to async/await. In particular, the next function that powers cursors was written with callbacks and would recursively call itself depending on the cursor type. For ChangeStreams, this function would call itself if there were no new changes to return to the user. After converting that code to async/await each recursive call created a new promise that saved the current async context. This would slowly build up memory usage if no new changes came in to unwind the recursive calls.
The function is now implemented as a loop, memory leak be gone!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 5.8.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 5.8.1 of the mongodb package!
saslprep updated to correct library.Fixes the import of saslprep to be the correct @mongodb-js/saslprep library.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
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 i…
The MongoDB Node.js team is pleased to announce version 5.8.0 of the mongodb package!
AutoEncrypter interface has been deprecatedThe 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.
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.
Because of internal options handling, a deprecation was emitted for tlsCertificateFile when using tlsCertificateKeyFile. That has been corrected.
ConnectionPoolCreatedEventIn 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.
AutoEncrypter interface (#3764) (9bb0d95)@aws-sdk/credential-providers version to 3.188.0 and zstd to ^1.0.0 (#3821) (39ff81d)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
wtimeout, j, and fsync options have been deprecated, please use wtimeoutMS and journal instead.
The MongoDB Node.js team is pleased to announce version 5.7.0 of the mongodb package!
wtimeout, j, and fsync options have been deprecated, please use wtimeoutMS and journal instead.
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 |
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 }}
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 }
}
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');
Take a look at the bson package's release notes!
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.
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 fixThe 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 deploymentssaslprep 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 TypeErrors.
This release includes a fix that prevents the driver throwing TypeErrors when attempting to use saslprep in bundled environments.
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.mapStarting 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.
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.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 5.6.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 5.6.0 of the mongodb package!
The MongoDB Node.js Driver now supports Node.js 20! 🎉
runCursorCommand APIWe have added the Db#runCursorCommand method which can be used to execute generic cursor commands. This API complements the generic Db#command method.
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.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Nothing published for this version
Nothing published for this version
The MongoDB Node.js team is pleased to announce version 5.5.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 5.5.0 of the mongodb package!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The db.command() API has a number of options deprecated that were incorrectly included in the typescript interface the method reportedly accepts. A ma…
The MongoDB Node.js team is pleased to announce version 5.4.0 of the mongodb package!
ChangeStream.tryNext Typescript fixWe 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.
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.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
NODE-4774: deprecate cursor forEach
The MongoDB Node.js team is pleased to announce version 5.3.0 of the mongodb package!
upsertedId to be null in UpdateResult (#3631) (4b5be21)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 5.2.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 5.2.0 of the mongodb package!
This release includes driver support for automatically obtaining Azure credentials when using automatic client side encryption. You can find a tutorial for using Azure and automatic encryption here: Use Automatic Queryable Encryption with Azure
Additionally, we have a number of minor bug fixes listed below.
NOTE: This release includes some experimental features that are not yet ready for use. As a reminder, anything marked experimental is not a part of the stable driver API and is subject to change without notice.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 5.1.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 5.1.0 of the mongodb package!
bigints in the driverThe driver now supports automatic serialization of JavaScript bigints to BSON.Longs. 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();
})()
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 5.0.1 of the mongodb package!
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.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Collection.insert, Collection.update, and Collection.remove methods have been removed in favor of their non-deprecated counterparts. You can read more…
The MongoDB Node.js team is pleased to announce version 5.0.0 of the mongodb package!
Node.js driver v5 emphazises the modernization of our API.
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.
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.
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.
@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.
We invite you to try the mongodb library and report any issues to the NODE project.
This alpha build is intended for internal testing only. Adopt at your own risk.
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)
The MongoDB Node.js team is pleased to announce version 4.17.2 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.17.2 of the mongodb package!
When enabling serverApi the driver's RTT mesurment logic (used to determine the closest node) still sent the legacy hello command "isMaster" causing the server to return an error. Unfortunately, the error handling logic did not correctly destroy the socket which would cause a leak.
Both sending the correct hello command and the error handling connection clean up logic are fixed in this change.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.17.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.17.1 of the mongodb package!
saslprep updated to correct library.Fixes the import of saslprep to be the correct @mongodb-js/saslprep library.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.17.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.17.0 of the mongodb package!
mongodb-js/saslprep is now installed by defaultUntil 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.
ConnectionPoolCreatedEventIn 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.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.16.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.16.0 of the mongodb package!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.15.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.15.0 of the mongodb package!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
NODE-4992: Deprecate methods and options that reference legacy logger
The MongoDB Node.js team is pleased to announce version 4.14.0 of the mongodb package!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.13.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.13.0 of the mongodb package!
We invite you to try the mongodb driver immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.12.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.12.1 of the mongodb package!
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.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Many thanks to @ImRodry for helping us fix the documentation for our deprecated callback overloads in this release!
The MongoDB Node.js team is pleased to announce version 4.12.0 of the mongodb package!
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.
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.
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.
Many thanks to @ImRodry for helping us fix the documentation for our deprecated callback overloads in this release!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.11.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.11.0 of the mongodb package!
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.
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.
Many thanks to those who contributed to this release!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
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…
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:
async/await syntax can yield the best experience with promise usage.require('util').callbackify(() => collection.findOne())(callback)collection.findOne().then(res => callback(null, res), err => callback(err))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:
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.9.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.9.1 of the mongodb package!
This is a bug fix release as noted below.
In fact, it did support it at run time and now the types correctly reflect that, along with the corresponding deprecations we made to the nested write…
The MongoDB Node.js team is pleased to announce version 4.9.0 of the mongodb package!
We have corrected an inconsistency with our writeConcern options in the type definitions where the MongoClient alleged to not support "writeConcern" as an option. In fact, it did support it at run time and now the types correctly reflect that, along with the corresponding deprecations we made to the nested writeConcern config settings.
Our index specification handling had a few peculiar edge cases that we have detailed below, we believe these are unlikely to affect a vast majority of users as the type definitions would have likely reported an error with the impacted usage. As a feature, the typescript definitions now support a javascript Map as a valid input for an index specification.
<details> <summary><strong>Index Specification Detailed Fixes</strong></summary> <br> <ul> <li>Map as a valid input type in TS definition</li> <li>Uses Map under the hood to ensure key order is preserved, fixed numeric index key order issue in combination with FLE usage</li> <li>Tuples passed at the top level to <code>createIndex</code> were incorrectly parsed as string input<ul> <li><code>createIndex(['myKey', 1])</code> would create <code>{ 'myKey': 1, '1': 1 }</code>. </li> <li>Now it's correctly detected if the second arg is one of the known index directions. </li> <li>For complex programmatic generation of indexes we recommend using a Map to avoid all the edge cases here.</li> </ul> </li> <li>Type strictness on this nesting of array (one or more)</li> <li>Type strictness for createIndexes aligned with createIndex<ul> <li>No longer accepts just Document, checks that the values are a known IndexDirection</li> </ul> </li> </ul> </details>
As per usual this release brings in the latest BSON release (v4.7.0) which added automatic UUID support. You can read more about that in the BSON release notes here!
Special thanks to the folks who contributed to this release!
oplogReplay flag support fixoplogReplay option as deprecated (#3337) (6c69b7d)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.8.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.8.1 of the mongodb package!
This patch comes with some bug fixes that are listed below as well as a quality of life improvement for nested keys in the UpdateFilter and Filter types. Thanks to @coyotte508 (#3328) for contributing this improvement!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.8.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.8.0 of the mongodb package!
Thanks to a contribution from @coyotte508, in this release you will now get auto-complete and type safety for nested keys in an update filter. See the example below:
client.connect() fixupIn our last release we made explicitly calling client.connect() before performing operations optional with some caveats. In this release client.startSession() can now be called before connecting to MongoDB.
NOTES:
- The only APIs that need the client to be connected before using are the legacy
collection.initializeUnorderedBulkOp()/collection.initializeOrderedBulkOp()builder methods. However, the preferredcollection.bulkWrite()API can be used without calling connect explicitly.- While executing operations without explicitly connecting may be streamlined and convenient, depending on your use case
client.connect()could still be useful to find out early if there is some easily detectable issue (ex. networking) that prevents you from accessing your database.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
All related APIs marked with @expiremental in the documentation. There are no guarantees that the APIs will not undergo breaking changes without prior…
The MongoDB Node.js team is pleased to announce version 4.7.0 of the mongodb package! Happy MongoDB World Day!
zstd compression is now supported by the NodeJS driver. To enable zstd compression, add it as a dependency in your project: npm install –save @mongodb-js/zstd. The add the option to your URI options: mongodb://host:port/db?compressors=zstd.
The Node driver has improved connection storm avoidance by limiting the number of connections that the driver will attempt to open to each server at a time. The number of concurrent connection attempts is set to 2 by default, but can be configured with a new MongoClient argument, maxConnecting. The following code example creates a new MongoClient that configures maxConnecting to 5.
const client = new MongoClient('MONGODB_URL', { maxConnecting: 5 });
The collection.watch function now supports a new option, showExpandedEvents. When showExpandedEvents is enabled, change streams will report the following events on servers 6.0 and later:
createIndexesdropIndexesmodifycreateshardCollectionOn servers 6.1.0 and later, showExpandedEvents will also show change stream events for the following commands:
reshardCollectionrefineCollectionShardKeyAs an example, the following code creates a change stream that has expanded events enabled on a collection:
const client = new MongoClient('MONGODB_URL');
await client.connect();
const collection = client.db('example-db').collection('example-collection');
const changeStream = collection.watch([], { showExpandedEvents: true });
Change streams now support pre and post images for update events. To enable pre and post images, the collection must be created with the changeStreamPreAndPostImages option enabled:
const collection = await db.createCollection(‘collectionName’, { changeStreamPreAndPostImages: { enabled: true }} )
Pre and post images can then be enabled on the change stream when the change stream is created:
const changeStream = collection.watch([], { fullDocumentBeforeChange: ‘required’ })
See the documentation on pre and post images for more information: https://www.mongodb.com/docs/v6.0/changeStreams/#change-streams-with-document-pre--and-post-images.
The driver now only processes the most recent server monitoring event if multiple heartbeat events are recorded in sequence before any can be processed. In serverless environments, this results in increased performance when a function is invoked after a period of inactivity as well as lower resource consumption.
The 5.0 server compatible release unintentionally broke the estimatedDocumentCount command on views by changing the implementation from the count command to aggregate and a collStats stage. This release fixes estimatedDocumentCount on views by reverting the implementation to use count.
Due to an oversight, the count command was omitted from the Stable API in server versions 5.0.0 - 5.0.8 and 5.1.0 - 5.3.1, so users of the Stable API with estimatedDocumentCount are recommended to upgrade their MongoDB clusters to 5.0.9 or 5.3.2 (if on Atlas) or set apiStrict: false when constructing their MongoClients.
If an operation is run before MongoClient.connect is called by the client, the driver will now automatically connect along with that first operation. This makes the repl experience much more streamlined, going right from client construction to your first insert or find. However, MongoClient.connect can still be called manually and remains useful for learning about misconfiguration (auth, server not started, connection string correctness) early in your application's startup.
Note: It's a known limitation that explicit sessions (client.startSession) and
initializeOrderedBulkOp,initializeUnorderedBulkOpcannot be used until MongoClient.connect is first called. Look forward to a future patch release that will correct these inconsistencies.
Clustered Collections can now be created using the createCollection method in the Node driver:
const client = new MongoClient('MONGODB_URL');
// No need to connect anymore! (see above)
const collection = await client.db(‘example-db’).createCollection(‘example-collection’, {
key: _id,
unique: true
});
More information about clustered indexes can be found on the official documentation page. https://www.mongodb.com/docs/upcoming/core/clustered-collections/
To enable the driver to use the new Automatic Encryption Shared Library instead of using mongocryptd, pass the location of the library in the auto-encryption extra options to the MongoClient. Example:
const client = new MongoClient(uri, {
autoEncryption: {
keyVaultNamespace: 'encryption.__keyVault',
kmsProviders: {
local: { key: 'localKey' }
},
extraOptions: {
cryptSharedLibPath: "/path/to/mongo_crypt_v1.dylib",
},
encryptedFieldsMap: {
"default.secretCollection": {
[
{
keyId: '_id',
path: 'ssn',
bsonType: 'string',
queries: { queryType: 'equality' }
}
]
},
},
},
})
Queryable Encryption is a beta feature that enables you to encrypt data in your application before you send it over the network to MongoDB while still maintaining the ability to query the encrypted data. With Queryable Encryption enabled, no MongoDB-managed service has access to your data in an unencrypted form.
Checkout the documentation: https://www.mongodb.com/docs/upcoming/core/queryable-encryption/queryable-encryption/
ATTENTION: This feature is included in this release as a beta preview. All related APIs marked with
@expirementalin the documentation. There are no guarantees that the APIs will not undergo breaking changes without prior notice.
Features:
Bug Fixes
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.6.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.6.0 of the mongodb package!
Our change stream document type and watch API have undergone some improvements! You can now define your own custom type for the top level document returned in a 'change' event. This is very useful when using a pipeline that significantly changes the shape of the change document (ex. $replaceRoot, $project operators). Additionally, we've improved the type information of the default change stream document to default to union of the possible events from MongoDB. This works well with typescript's ability to narrow a Discriminated Union based on the operationType key in the default change stream document.
Prior to this change the ChangeStreamDocument inaccurately reflected the runtime shape of the change document. Now, using the union, we correctly indicate that some properties do not exist at all on certain events (as opposed to being optional). With this typescript fix we have added the properties to for rename events, as well as lsid, txnNumber, and clusterTime if the change is from within a transaction.
NOTE: Updating to this version may require fixing typescript issues. Those looking to adopt this version but defer any type corrections can use the watch API like so: .watch<any, X>(). Where X controls the type of the change document for your use case.
Check out the examples and documentation here.
Operations will now be directed towards servers that have fewer in progress operations. This distributes load across servers and prevents overwhelming servers that are already under load with additional requests.
This release includes some experimental features that are not yet ready for use. As a reminder, anything marked experimental is not a part of the official driver API and is subject to change without notice.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version v4.6.0-alpha.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version v4.6.0-alpha.0 of the mongodb package!
This release is for internal testing - NOT intended for use production.
The MongoDB Node.js team is pleased to announce version 4.5.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.5.0 of the mongodb package!
This release includes a number of enhancements noted below.
comment option supportThe comment option is now widely available: by setting a comment on an operation you can trace its value in database logs for more insights.
collection.insertOne(
{ name: 'spot' },
{ comment: { started: new Date() } }
)
An example of a log line, trimmed for brevity. We can see the timestamp of the log and the time created on our client application differ.
{
"t": { "$date": "2022-04-04T16:08:56.079-04:00" },
"attr": {
"commandArgs": {
"documents": [ { "_id": "...", "name": "spot" } ],
"comment": { "started": { "$date": "2022-04-04T20:08:56.072Z" } } }
}
}
This release includes a fix for serverless environments where transient serverHeartBeatFailure events that could be corrected to serverHeartBeatSucceeded events in the next tick of the event loop were nonetheless handled as an actual issue with the client's connection and caused unnecessary resource clean up routines.
It turns out that since Node.js handles timeout events first in the event loop, socket timeouts expire while the FaaS environment is dormant and the timeout handler code is the first thing that runs upon function wake prior to checking for any data from the server. Delaying the timeout handling until after the data reading phase avoids the sleep-induced timeout error in the cases where the connection is still healthy.
Typescript 4.7 may not be out yet but in preparation for its release we've fixed issues compiling against that version. The main new obstacle was defaulting generic arguments that require that the constraining condition enforce similarity with the defaulted type. You may notice that our change stream watch<T extends Document = Document>() methods now requires that T extends Document, a requirement that already had to be met by the underlying ChangeStreamDocument type.
comment field (#3167) (4e2f9bf)watch type parameter to extend ChangeStream type parameter (#3183) (43ba9fc)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.4.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.4.1 of the mongodb package!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
In the 4.0.0 release of the driver, the deprecated collection.count() method was inadvertently changed to behave like collection.countDocuments(). In…
The MongoDB Node.js team is pleased to announce version 4.4.0 of the mongodb package!
This release includes a few new features described below.
KMIP can now be configured as a KMS provider for CSFLE by providing the KMIP endpoint in the kmsProviders option.
Example:
new MongoClient(uri, { autoEncryption: { kmsProviders: { kmip: { endpoint: 'host:port' }}}})
Custom TLS options can now be provided for connection to the KMS servers on a per KMS provider basis.
Example:
new MongoClient(uri, { autoEncryption: { tlsOptions: { aws: { tlsCAFile: 'path/to/file' }}}})
Valid options are tlsCAFile, tlsCertificateKeyFile, tlsCertificateKeyFilePassword and all accept strings as values: a string path to a certificate location on the file system or a string password.
Hostname canonicalization when using GSSAPI authentication now accepts 'none', 'forward', and 'forwardAndReverse' as auth mechanism properties. 'none' will perform no canonicalization (default), 'forward' will perform a forward cname lookup, and 'forwardAndReverse' will perform a forward lookup followed by a reverse PTR lookup on the IP address. Previous boolean values are still accepted and map to false -> 'none' and true -> 'forwardAndReverse'.
Example:
new MongoClient('mongodb://user:pass@host:port/db?authMechanism=GSSAPI&authMechanismProperties=CANONICALIZE_HOST_NAME=forward');
For cases when the service host name differs from the connection’s host name (most likely when creating new users on localhost), a SERVICE_HOST auth mechanism property may now be provided.
Example:
new MongoClient('mongodb://user:pass@host:port/db?authMechanism=GSSAPI&authMechanismProperties=SERVICE_HOST:example.com')
In the 4.0.0 release of the driver, the deprecated collection.count() method was inadvertently changed to behave like collection.countDocuments(). In this release, we have updated the collection.count() behavior to match the legacy behavior:
collection.count will behave the same as collection.countDocuments and perform a collection scan.collection.count will behave the same as collection.estimatedDocumentCount and rely on collection metadata.We also deprecated the cursor.count() method and will remove it in the next major version along with collection.count(); please use collection.estimatedDocumentCount() or collection.countDocuments() instead.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.3.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.3.1 of the mongodb package!
In this patch release, we address the limitation introduced in 4.3.0 with the dot notation Typescript improvements and recursive types.
Namely, this fix removes compilation errors for self-referential types.
Note that this fix still has the following limitations:
any after the first level of recursion for self-referential typesinterface Node {
next: Node | null;
}
declare const collection: Collection<Node>;
// no error here even though `next` is of type `Node | null`
collection.find({
next: {
next: 'asdf'
}
});
interface A {
b: B;
}
interface B {
a: A;
}
declare const mutuallyRecursive: Collection<A>;
// this will throw an error because there is indirect recursion
// between types (A depends on B which depends on A and so on)
mutuallyRecursive.find({});
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.3.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.3.0 of the mongodb package!
This release includes SOCKS5 support and a couple of other important features and bug fixes that we hope will improve your experience with the node driver.
The SOCKS5 options can be configured via the proxyHost, proxyPort, proxyPassword and proxyUsername options in the connection string passed to the MongoClient instance. Big thanks to @addaleax for helping with this feature!
The other notable features address performance and TypeScript as detailed below.
The original release of the 4.x driver relied on a new version of the BSON library that enables UTF-8 validation by default, resulting in noticeable performance degradation over the 3.x driver when processing over string data. This release introduces an option to opt out of this validation by specifying enableUtf8Validation: false at the client, database, collection, or individual operation level.
For example:
// disable UTF-8 validation globally on the MongoDB client
const client = new MongoClient('mongodb://localhost:27017', { enableUtf8Validation: false });
// disable UTF-8 validation for a particular operation
const client = new MongoClient('mongodb://localhost:27017');
const db = client.db('database name');
const collection = db.collection('collection name');
await collection.find({ name: 'John Doe'}, { enableUtf8Validation: false });
Thanks to an amazing contribution from @avaly we now have support for key auto-completion and type hinting on nested documents! MongoDB permits using dotted keys to reference nested keys or specific array indexes within your documents as a shorthand for getting at keys beneath the top layer. Typescript's Template Literal types allow us to take the interface defined on a collection and calculate at compile time the nested keys and indexes available.
For example:
interface Human {
name: string;
age: number;
}
interface Pet {
name: string
bestFriend: Human
}
const pets = client.db().collection<Pet>('pets');
await pets.findOne({ 'bestFriend.age': 'young!' }) // typescript error!
Here's what autocomplete suggests in VSCode: <img width="171" alt="Screen Shot 2022-01-06 at 5 29 17 PM" src="https://user-images.githubusercontent.com/81593090/148467749-ba4698fd-8a57-4656-ac5e-f02acf52d90f.png">
WARNING: There is a known shortcoming to this feature: recursive types can no longer be used in your schema. For example, an interface that references itself or references another schema that references back to the root schema cannot be used on our Collection generic argument. Unlike at runtime where a "recursive" shaped document has an eventual stopping point we don't have the tools within the language to declare a base case enumerating nested keys. We hope this does not cause friction when upgrading driver versions: please do not hesitate to reach out with any feedback you have about this feature.
We have also enhanced the type inference for the _id type. Now, when performing operations on a collection, the following holds true based on the type of the schema:
_id is specified on the schema, it is inferred to be of type ObjectId and is optional on inserts._id is specified on the schema as required, then the _id type is inferred to be of the specified type and is required on inserts._id is specified on the schema as optional, it is inferred to be of the specified type and is optional on inserts: this format is intended to be used with the pkFactory option in order to ensure a consistent _id is assigned to every new document.enableUtf8Validation option (#3074) (4f56409)GridFSBucketWriteStream.prototype.end() return this for compat with @types/node@17.0.6 (#3088) (7bb9e37)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.2.2 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.2.2 of the mongodb package!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.2.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.2.1 of the mongodb package!
This release fixes an issue with the dbName being overridden by the authSource option. Additionally, we have ensured that cursors re-run server selection when fetching additional batches, which should reduce issues encountered in long running function as a service environments.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Additionally, in this release, we’ve marked collection.mapReduce() as deprecated. The same functionality can be replicated in the much more flexible a…
This release includes a number of features we’re happy to announce. You can now run aggregation pipelines that write write to a MongoDB collection using $out and $merge stages on secondaries! We’ve added an option to limit the number of hosts the driver will connect to when using SRV DNS lookups to manage your host addresses. And lastly, the authorizedCollection option is now usable on the db.listCollections() function.
Additionally, in this release, we’ve marked collection.mapReduce() as deprecated. The same functionality can be replicated in the much more flexible aggregation pipeline. Visit Map-Reduce to Aggregation Pipeline to learn more.
The minimum supported MongoDB version is 3.6. Attempts to connect to a MongoDB server older than 3.6 will result in an error. Please take note of the MongoDB Software Lifecycle Schedules for timeframes of supported server versions.
authorizedCollections option to the db.listCollections method (#3021) (e1234a7)defaultTransactionOptions with POJO rather than ReadConcern instance (#3032) (53b3164)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
This release includes a couple of bug fixes as noted below:
This release includes a couple of bug fixes as noted below:
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.1.3 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.1.3 of the mongodb package!
This release includes a couple of TypeScript fixes as noted below:
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.1.2 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.1.2 of the mongodb package!
This release addresses a number of bug fixes, please peruse the list below for more information on each fix.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
NODE-3511: deprecate fullResponse and remove associated buggy code paths
The MongoDB Node.js team is pleased to announce version 4.1.1 of the mongodb package!
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!
findOne() once again correctly returns null when no match is found instead of undefined. This change was unintentional and not consistent with our other APIs. It slipped through testing due to the nature of undefined and null 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:
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.
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!
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.1.0 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.1.0 of the mongodb package!
This release includes load balancer support, intended for use with the beta Serverless platform. When using the driver with Serverless, the SRV URI will automatically put the driver into this mode. When wanting to use a non-SRV URI one must add the loadBalanced=true option to the URI to put the driver into this mode. Being in this mode enables the driver to properly route transactions and cursors to the correct service behind the load balancer.
The release also fixes an important bug where the original release of the v4 driver enabled command monitoring by default, which caused many reported observations of performance degradation when upgrading from v3 of the driver. Command monitoring is now once again disabled by default and must be enabled by passing in { monitorCommands: true } to the client if desired.
| void in declaration of Promise overload of rename() (#2922) (58c1e84)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.0.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 4.0.1 of the mongodb package!
This release fixes two small but important bugs from our 4.0.0 release:
We hope this improves your upgrade experience!
db() before MongoClient is connected (#2889) (51ea86d)We invite you to try the mongodb library immediately, and report any issues to the NODE project.
Below are only the changes since our last beta release, for the full set of breaking changes look at the upgrade guide here and for the full set of ne…
The MongoDB Node.js team is delighted to announce the major version release 4.0.0 of the MongoDB Node.js Driver!
We finally did it! The major version release of the MongoDB driver is now generally available! This release represents over a year's worth of effort that couldn't have been done without stellar contributions from the community and our Node.js DBX team. We hope you give it a try and are able to upgrade smoothly! :tada:
The biggest news is our migration to Typescript :partying_face: offering first class support of type definitions in the driver itself.
Some cool new MongoDB 5.0 features now supported in the driver are:
Below are only the changes since our last beta release, for the full set of breaking changes look at the upgrade guide here and for the full set of new features, take a look here.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
As a breaking change in this release we now make use of the new MongoDriverError and MongoServerError to clarify where the issue arose from. All of th…
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.6 of the mongodb package!
This is on the larger side of the beta releases we've done so far we're getting closer to calling this version official.
As a breaking change in this release we now make use of the new MongoDriverError and MongoServerError to clarify where the issue arose from. All of the errors that our driver throws subclass from MongoError so its possible to filter in catch blocks using instanceof. Take a look at this example:
// without calling .connect()
await c.insertOne({ a: 1 })
// Uncaught MongoDriverError: MongoClient must be connected before calling MongoClient.prototype.db
// at MongoClient.db (lib/mongo_client.js)
await c.insertOne({ _id: /a/ })
// Uncaught MongoServerError: can't use a regex for _id
// at lib/operations/insert.js {
// index: 0,
// code: 2
// }
Here's the highlights:
.find() and update specifiers in findOneAndUpdate() await collection.insertOne({ a: new BSONRegExp('(?-i)AA_') })
await collection.findOne({ a: new BSONRegExp('(?-i)AA_') }, { bsonRegExp: true })
// { _id: ObjectId, a: BSONRegExp { pattern: '(?-i)AA_', options: '' } }
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.5 of the driver!
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.5 of the driver!
This release further improves our TypeScript support with consistent enum naming and a better list of exported types.
We invite you to try the mongodb package immediately, and report any issues to the NODE project.
We have a few breaking changes listed below, notably the node driver now aligns with other drivers by using the returnDocument option when determining…
The MongoDB Node.js team is pleased to announce version 4.0.0.beta.4 of the driver.
This beta release brings optional support for Typescript generics when defining your collections
// Example:
interface Pet {
type: 'cat' | 'dog' | 'fish'
}
const collection = db.collection<Pet>()
await collection.findOne({}).toArray() // returns Pet[]
as well as strong typing for events emitted by the MongoClient. For example, when listening to .on('commandStarted' event => ...), event here will be a CommandStartedEvent object.
We have a few breaking changes listed below, notably the node driver now aligns with other drivers by using the returnDocument option when determining whether to return the document before or after the update in findOneAndUpdate and findOneAndReplace.
NODE-2995: Add shared metadata MongoClient (#2772) (9073d54)
NODE-3074: update estimated document count for v1 api (#2764) (146791c)
NODE-3109: prevent servername from being an IP (#2771) (27089be)
NODE-3166: allowInvalidHostnames and allowInvalidCertificates flags are ignored (#2784) (a769cf8)
NODE-3174: Preserve sort key order for numeric string keys (#2788) (440de41)
NODE-3176: handle errors from MessageStream (#2780) (76b110e)
NODE-3194: Ignore undefined and null options in MongoClient constructor (#2800) (8bb92f9)
NODE-3197: revert setImmediate in waitQueue (#2802) (6c0dfef)
NODE-3206: Make distinct use any[] type instead of Document[] (#2795) (b45e3b3)
NODE-3219: topology no longer causes close event (#2792) (6cd982f)
NODE-1812: replace returnOriginal with returnDocument option (#2803) (1cdc8a8)
NODE-3157: update find and modify interfaces for 4.0 (#2799) (29512da)
We invite you to try the driver immediately, and report any issues to the NODE project.
To try the beta use the following command:
npm install mongodb@4.0.0-beta.4
Thanks very much to all the community members who contributed to this release!
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.3 of the driver
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.3 of the driver
This release brings us closer to the RC release for the fully typescript enabled version 4.0.0 of the driver. You can expect a full migration and detailed list of changes with the upcoming RC.
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.2 of the driver
The MongoDB Node.js team is pleased to announce version 4.0.0-beta.2 of the driver
This release brings us closer to the RC release for the fully typescript enabled version 4.0.0 of the driver. You can expect a full migration and detailed list of changes with the upcoming RC.
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.0/HISTORY.md
This beta release addresses a few bugs relating to using CSFLE with the beta version of the driver. As well as a fix for BulkWriteResult and BulkWrite
This beta release addresses a few bugs relating to using CSFLE with the beta version of the driver. As well as a fix for BulkWriteResult and BulkWriteError to correctly reflect the operation's result information.
You can take a look at the raw updates list in our HISTORY.md file, we are intending to do a complete rundown of features and fixes with the v4.0.0 release.
You can give it a try with:
npm install mongodb@beta
If you have any suggestions about clarifying documentation or if you run into any issues or have any feature ideas please let us know! You can make an account and submit tickets to our JIRA project here.
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.0/HISTORY.md
The MongoDB Node.js team is pleased to announce a beta version v4.0.0-beta.0 of the driver.
The MongoDB Node.js team is pleased to announce a beta version v4.0.0-beta.0 of the driver.
A major motivation for releasing this beta was the migration of the entire code base to TypeScript. While we took special care to ensure a smooth transition, we imagine such a dramatic change might reveal unexpected issues. This beta release makes it easy to easily check compatibility with your application and make use of the included type definitions.
Additionally, we are publishing an early version of the new API documentation https://mongodb.github.io/node-mongodb-native/4.0.
You can take a look at the raw updates list in our HISTORY.md file, we are intending to do a complete rundown of features and fixes with the v4.0.0 release.
You can give it a try with:
npm install mongodb@beta
If you have any suggestions about clarifying documentation or if you run into any issues or have any feature ideas please let us know! You can make an account and submit tickets to our JIRA project here.
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.0/HISTORY.md
The MongoDB Node.js team is pleased to announce version 3.7.4 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 3.7.4 of the mongodb package!
This release fixes a bug that throws a type error when SCRAM-SHA-256 is used with saslprep in a webpacked environment.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 3.7.3 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 3.7.3 of the mongodb package!
Full Changelog: https://github.com/mongodb/node-mongodb-native/compare/v3.7.2...v3.7.3
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 3.7.2 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 3.7.2 of the mongodb package!
This release contains a fix for optional require of dependencies on yarn berry.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
The MongoDB Node.js team is pleased to announce version 3.7.1 of the mongodb package!
The MongoDB Node.js team is pleased to announce version 3.7.1 of the mongodb package!
This release contains an internal improvement that makes our monitor utilize the new hello handshake for monitoring when available.
We invite you to try the mongodb library immediately, and report any issues to the NODE project.
One column per quarter.