The official MongoDB Node.js driver
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 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 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.
ConnectionPoolCreatedEvent
In 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.
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.
ConnectionPoolCreatedEvent
In 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 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 TypeError
s.
This release includes a fix that prevents the driver throwing TypeError
s 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.map
Starting 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 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 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.
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 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.
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.