npm / mongodb
mongodb
What changed in mongodb 4 to 7, from its official release notes, upgrade guides and advisories. Also covers @types/mongodb. Sources checked 2026-11-30.
152 breaking1 security11 deprecations16 new APIs and options1 performance28 behavior and defaults1 tooling22 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initmongodb 7110 changes
Breaking changes 58
When unset on MongoClient, the driver no longer forces true, allowing the runtime process default to apply; explicit driver options still take precedence.
Only NamespaceNotFound server errors are swallowed; all other errors are thrown.
Construction now fails when ENVIRONMENT and OIDC_CALLBACK or OIDC_HUMAN_CALLBACK are provided in any combination, preventing the associated OIDC bearer token leak.
For unordered bulk writes mixing inserts with updates or deletes, insertedIds is now keyed by each insert's operation index rather than a running insert count.
In the three-argument overload, index options are passed to the server as written, enabling newer server options without driver allow-list updates; invalid options are no longer filtered.
Its return type is now
ClientEncryptionRewrapManyDataKeyResultinstead of an anonymous type; runtime behavior is unchanged.timeoutMS and timeoutMode are deprecated no-ops: operations no longer time out because of them. Use the per-stage timeout options instead.
The driver no longer supports MongoDB 4.2 or older servers and throws an error when connecting to them.
Closing a client now closes checked-out connections across all servers, interrupting in-flight operations promptly.
String replaces the TextPreview algorithm for Queryable Encryption string queries.
StringOpts replaces TextOpts for Queryable Encryption string queries.
On replica sets, server deprioritization is restricted to overload errors.
Wildcard matching now requires full subdomain or path matches, preventing partial suffix matches from being accepted.
Aggregate with write concern and explain now throws a MongoServerError instead of throwing client-side.
TypeScript now restricts the filename to the default crypt_shared library name or a path ending in that filename.
TypeScript now restricts the filename to the default mongocryptd name or a path ending in that filename.
This package is now required for MONGODB-AWS authentication.
The beta namespace was removed; resource management moved into the driver.
The deprecated CancellationToken type has been removed.
The deprecated ClientMetadataOptions type has been removed.
The deprecated transaction property has been removed from ClientSession.
The deprecated CloseOptions type has been removed.
retryWrites has been removed from CommandOperationOptions; it is a global MongoClient option.
The noResponse option has been removed; it was never intended for public APIs and did not work properly.
This internal ClientMetadata property is no longer exposed in the public API.
This internal ClientMetadata property is no longer exposed in the public API.
The deprecated autoIndexId option has been removed.
Dropping a collection returns false instead of throwing when the namespace is not found.
The deprecated batchSize option has been removed from FindOneOptions.
The deprecated limit option has been removed from FindOneOptions.
The deprecated noCursorTimeout option has been removed from FindOneOptions.
FindOptions no longer accepts a generic type parameter.
Cursors no longer set a default batchSize of 1000 for getMore; it is set only when explicitly configured for the cursor.
The deprecated aliases option has been removed.
The deprecated contentType option has been removed.
The deprecated aliases property has been removed.
The deprecated contentType property has been removed.
The optional peer dependency minimum version is 7.0.0; support for version 2.x is dropped.
connect now runs a handshake regardless of whether credentials are defined, making fail-fast precondition checks more consistent across environments.
This internal ClientMetadata property is no longer exposed in the public API.
This internal ClientMetadata property is no longer exposed in the public API.
This internal ClientMetadata property is no longer exposed in the public API.
The deprecated useNewUrlParser option has been removed.
The deprecated useUnifiedTopology option has been removed.
The driver now uses bson@7.0.0; BSON functionality re-exported from the driver is subject to the BSON V7 release-note changes.
Explicit credentials in the URI or options are no longer accepted; AWS credentials are fetched through the required AWS SDK.
The optional peer dependency minimum version is raised to 7.0.0, dropping support for 6.x.
The unsupported MONGODB-CR authentication mechanism has been removed.
The optional peer dependency minimum version is 7.0.0; support for versions 1.x and 2.x is dropped.
This internal ClientMetadata property is no longer exposed in the public API.
This internal ClientMetadata property is no longer exposed in the public API.
This internal ClientMetadata property is no longer exposed in the public API.
The deprecated minWireVersion property has been removed.
The deprecated ResumeOptions type has been removed.
The deprecated ServerCapabilities type has been removed.
Cursor and ChangeStream stream() no longer accepts a transform function; ReadableStream.map() can be used instead.
MongoClient, ClientSession, ChangeStream, and cursors implement Symbol.asyncDispose for explicit resource management; this support is experimental.
The deprecated Transaction type has been removed.
Security 1
SRV host names are checked in normalized form, addressing a host-name verification security issue and allowing case-different connection-string host names to connect.
Deprecations 5
SelectServerOptions is deprecated because it is not intended for public use and will become internal in the next major release.
The prefixPreview query type is deprecated and will be removed in a future release.
The substringPreview query type is deprecated and will be removed in a future release.
The suffixPreview query type is deprecated and will be removed in a future release.
The unused new_collection option is deprecated and can be safely removed with no behavioral change.
New APIs and options 10
Adds a three-argument overload separating index options from createIndexes command options; the existing two-parameter overload remains supported for now.
Adds a host name suffix constraint for every host returned by an SRV lookup; it can be configured on the client or in the connection string.
Adds a synchronous client option that decides whether a host returned by an SRV lookup may be used; it must return a boolean.
Support was added for baseBackoffMS alongside an update to client backpressure backoff.
Set this callback on ClientEncryption or auto-encryption options to connect to KMS hosts through an HTTP proxy; the driver performs the KMS TLS handshake over the returned socket.
Returns the number of documents remaining in the change stream from the last batch, allowing callers to check for buffered documents before invoking async methods.
The token bucket is optional in client backpressure.
When enabled, the driver deprioritizes servers that return overload errors during retry server selection; defaults to false.
Configures the maximum number of retries during server overload; defaults to 2, and 0 disables overload retries.
Experimental MongoClient option for injecting core Node.js APIs, including the os module, for alternative runtimes or restricted environments.
Performance 1
insertMany and bulkWrite serialize each document once and reuse the resulting bytes for batch sizing and commands, reducing BSON-encoding CPU and event-loop blocking.
Behavior and default changes 23
The
@experimentaltag was removed from this feature, which is no longer experimental.The
@experimentaltag was removed from this feature, which is no longer experimental.The
@experimentaltag was removed from this feature, which is no longer experimental.The
@experimentaltag was removed from this feature, which is no longer experimental.The
@experimentaltag was removed from this feature, which is no longer experimental.helloandisMastercommands on monitoring connections are never compressed, even when compressors are configured.Uses Node.js' built-in zstd implementation when available, so Node.js 22.15.0+ no longer requires
@mongodb-js/zstd; older Node.js versions continue to use that package.The driver retries overload errors only when a retry is expected not to worsen server conditions, improving performance for MongoDB 9.0's Intelligent Workload Management.
The prefix query type is now generally available for Queryable Encryption string queries.
The substring query type is now generally available for Queryable Encryption string queries.
The suffix query type is now generally available for Queryable Encryption string queries.
The async disposal methods on MongoClient, ClientSession, ChangeStream, and cursors are now officially supported, enabling await using for automatic cleanup without experimental flags.
The maximum wire version and maximum server version were bumped to 29 in preparation for MongoDB LTS (v9.0).
Retry loops use exponential backoff and jitter.
The driver uses standard Uint8Array APIs and globalThis.crypto instead of Node-specific Buffer and crypto APIs, improving compatibility with non-Node.js runtimes.
The default OIDC allowed-host list now supports hosts matching *.mongo.com.
The driver replaces Node-specific APIs with standards-based equivalents and explicitly imports node:process, improving compatibility with alternate runtimes.
Connection establishment failures no longer clear the pool, preventing unnecessary connection churn when server-side connection rate limiting rejects requests.
When retrying a command, server selection deprioritizes servers to improve stability and reduce repeated targeting of overloaded or previously failed servers.
A custom AWS credential provider now takes the highest precedence over other AWS authentication methods.
Change streams no longer filter $changeStream stage options, allowing options to reach the server even before they are in public type definitions.
close only attempts session cleanup when the topology supports sessions.
Errors thrown during encryption are now subclasses of MongoError.
Fixes and other changes 12
The single-parameter overload is no longer deprecated; the overload mixing command and index options remains deprecated, and a separate-options overload is not deprecated.
A
$metasort direction in[field, direction]form now works consistently with the object and nested-array forms.GridFS download, delete, rename, and upload abort queries now match file IDs with
$eq; command monitoring and logs show the explicit operator.A failed OIDC token fetch now affects only the operation that triggered it; later operations can attempt a new token fetch without restarting the process.
The default os adapter now loads through dynamic import, so constructing a MongoClient in bundled ESM output no longer throws
ReferenceError: require is not defined.Write operations in causally consistent sessions now include readConcern.afterClusterTime, maintaining the “read your own writes” guarantee across primary failovers in sharded clusters.
Explicit UTF-8 string conversion fixes SCRAM authentication in non-Node.js environments such as Deno and other web-compatible runtimes.
The driver now applies TCP keep-alive and no-delay settings after TLS socket creation, preventing settings from being silently ignored.
OIDC reauthentication now succeeds when MongoClient is configured with promoteValues: false.
Aggregations using $merge or $out now respect secondary and secondaryPreferred read preferences instead of forcing execution on the primary.
The options parameter is now correctly marked optional in the TypeScript definition.
The PoolClearedError error label typo is fixed from PoolRequstedRetry to PoolRequestedRetry.
mongodb 676 changes
Breaking changes 62
timeoutMode is deprecated and has no effect starting in this release.
timeoutMS is deprecated and has no effect; operations no longer time out because of it. Use per-stage timeouts instead.
The transform option is deprecated and removed in favor of Stream#map; CursorStreamOptions will be removed in 7.0.0.
The addUser API is removed.
The options interface associated with the removed addUser APIs has also been removed.
The deprecated API has been removed; applications can send the createUser command directly.
Unsupported options are removed from admin.command.
readConcern and writeConcern options are no longer handled by the driver; attach these properties to the command document instead.
AutoEncrypter is made internal.
Boolean options now accept only true and false.
The driver adopts bson v6.
Duplicate BulkWriteResult accessors are removed.
The deprecated method has been removed; use insertedIds instead.
The deprecated method has been removed; use upsertedIds or getUpsertedIdAt(index) instead.
The deprecated property has been removed; use insertedCount instead.
The deprecated property has been removed; use matchedCount instead.
The deprecated property has been removed; use modifiedCount instead.
The deprecated property has been removed; use deletedCount instead.
The deprecated property has been removed; use upsertedCount instead.
Callbacks are removed from encrypt, decrypt, and createDataKey.
Callback support has been removed; asynchronous calls use promises.
A session from one client cannot be used on another.
The collection.stats API is removed.
The interface associated with collection.stats has been removed.
The transaction API no longer returns the command result.
Repeated options in a connection string are validated.
Unneeded fields are removed from ConnectionPoolCreatedEvent.options.
The TypeScript return type now reflects that the method returns the DataKey's insertedId, not a DataKey.
Unsupported options are removed from db.command.
readConcern and writeConcern options are no longer handled by the driver; attach these properties to the command document instead.
EvalOperation is removed.
EvalOptions is removed.
This static constant has been removed because the class no longer emits its own events.
This static constant has been removed because the class no longer emits its own events.
The stream now relies on Node.js Writable methods and event handling; finish and drain no longer receive the GridFSFile document, which is available as gridFSFile on the stream.
The findOneAndX family returns only the found document or null by default; set includeResultMetadata to true to retain the previous ModifyResult behavior.
includeResultsMetadata is false by default.
Deprecated keep alive options are removed.
The deprecated option has been removed; TCP keep alive is always on and set to 30000ms.
Kerberos compatibility is bumped to ^2.0.1.
MongoClient.autoEncrypter is made internal.
The driver adopts mongodb-client-encryption v6.
The optional peer dependency minimum is raised to 6.0.0; useful public APIs formerly exposed by this package have moved into the driver.
mongodb-js/saslprep is added as a required dependency.
MongoError is marked for internal use; Node 14 cause assignment logic is removed.
Driver helpers now throw this error when given a session from a different MongoClient.
The minimum supported Node.js version was updated.
Support for onKMSProvidersRefresh is dropped.
An empty readPreferenceTags value in a connection string is now parsed as an empty tag document.
SOCKS proxy support now requires installing socks as a peer dependency; it is no longer installed automatically.
Deprecated ssl options are removed.
The deprecated option has been removed; use tlsCAFile instead.
The deprecated option has been removed; use tlsCertificateKeyFile instead.
The deprecated option has been removed; use tlsCRLFile instead.
The deprecated option has been removed; use tlsCertificateKeyFile instead.
The deprecated option has been removed; use tlsCertificateKeyFilePassword instead.
The deprecated option has been removed; use tlsAllowInvalidCertificates instead.
TLS files are now read asynchronously on first connection rather than synchronously during MongoClient construction; file errors occur when connecting.
The deprecated option has been removed; use tlsCertificateKeyFile instead.
withSession returns the executor result.
withTransaction returns the executor result.
The optional peer dependency minimum is raised from 1.0.0 to 1.1.0.
Deprecations 6
noResponse is deprecated as unused and will be removed in 7.0.0.
cancellationToken is deprecated as unused and will be removed in 7.0.0.
AWS_SESSION_TOKEN is deprecated and will be removed in 7.0.0; URI and client options for AWS variables will no longer be respected.
MongoError and subclass constructors are now for internal use only and may change outside major versions.
Using useNewUrlParser emits a deprecation warning.
Using useUnifiedTopology emits a deprecation warning.
New APIs and options 2
The socks package can be installed optionally.
A CRL file can be provided through tlsCRLFile.
Behavior and default changes 3
GridFSBucketWriteStream uses the implementer Writable methods.
MongoCryptError is now a subclass of MongoError.
TLS files are read asynchronously.
Fixes and other changes 3
The class no longer manually emits events handled by Node.js stream logic.
tlsCertificateKeyFile now maps to cert and key.
The withTransaction return type is fixed.
mongodb 533 changes
Breaking changes 30
The abstract cursor return type changed.
The digestPassword option is removed.
The interface is removed in favor of AsyncGenerator.
This package is now an optional peer dependency and must be installed manually to use the native AWS SDK for authentication.
The driver no longer includes AWS SDK modules by default.
The driver now exports a BSON namespace, including BSON.EJSON APIs; importing BSON types and APIs from the driver helps ensure serialization consistency.
The bson-ext import was removed.
The lastop and optime fields were removed from bulk results.
The opTime property is removed.
The keepGoing option is removed.
The type no longer has the publicly enumerable result property.
The public API no longer supports callbacks; use Promises or the mongodb-legacy package for callback support.
Support for client encryption versions earlier than 2.3.0 was dropped.
Removed in favor of the non-deprecated insert counterpart.
Removed in favor of the non-deprecated remove counterpart.
Removed in favor of the non-deprecated update counterpart.
The TypeScript compilation target changed to ES2020, which may affect the runtime compatibility of compiled code.
Cursor close options were removed.
Support for custom promise libraries was removed.
The Kerberos option is removed.
The legacy logger was removed.
The collection mapReduce helper was removed.
The ObjectID type is removed in favor of ObjectId.
The export that allowed specifying a custom Promise library is removed.
The slaveOk options were removed.
The slaveOk options and method are removed in favor of secondaryOk.
Only snappy 7 or later is supported.
The unref API was removed.
The write concern failure event behavior changed in relation to ok 1.
The method is removed.
New APIs and options 1
An experimental type retains strict type checking capabilities for queries that use dot notation.
Behavior and default changes 1
Strict type checking for dot-notation CRUD filters is no longer enabled by default.
Fixes and other changes 1
The driver closes a cursor when a loop exits early.
mongodb 413 changes
Breaking changes 2
Using a change stream as an iterator and an emitter concurrently now results in an error.
MD5 hashing has been removed from the GridFS API.
New APIs and options 3
Adds time-series options to db.createCollection, allowing developers to create time-series collections.
Adds MongoRuntimeError and defines its child error classes.
Enables snapshot reads on secondary nodes.
Behavior and default changes 1
Defaults the ChangeStream generic type to Document.
Tooling 1
The driver now provides first-class support for type definitions.
Fixes and other changes 6
Fixes errors when a ChangeStream is used concurrently as an iterator and an emitter.
Uses hello for monitoring when it is supported.
Fixes the result type definition for listCollections.
Accepts tls=false in mongodb+srv connection strings.
Fixes bulk operations ignoring provided sessions.
Fixes watch method types on MongoClient and Db.