v6.5.0
版本发布时间: 2024-03-12 03:11:36
mongodb/node-mongodb-native最新发布版本:v6.9.0(2024-09-13 01:12:41)
6.5.0 (2024-03-11)
The MongoDB Node.js team is pleased to announce version 6.5.0 of the mongodb
package!
Release Notes
Bulk Write Operations Generate Ids using pkFactory
When performing inserts, the driver automatically generates _id
s for each document if there is no _id
present. By default, the driver generates ObjectId
s. An option, pkFactory
, can be used to configure the driver to generate _id
s that are not object ids.
For a long time, only Collection.insert
and Collection.insertMany
actually used the pkFactory
, if configured. Notably, Collection.bulkWrite()
, Collection.initializeOrderedBulkOp()
and Collection.initializeOrderedBulkOp()
always generated ObjectId
s, regardless of what was configured on collection.
The driver always generates _id
s for inserted documents using the pkFactory
.
[!CAUTION] If you are using a
pkFactory
and performing bulk writes, you may have inserted data into your database that does not have_id
s generated by thepkFactory
.
Fixed applying read preference to commands depending on topology
When connecting to a secondary in a replica set with a direct connection, if a read operation is performed, the driver attaches a read preference of primaryPreferred
to the command.
Fixed memory leak in Connection layer
The Connection class has recently been refactored to operate on our socket operations using promises. An oversight how we made async network operations interruptible made new promises for every operation. We've simplified the approach and corrected the leak.
Query SRV and TXT records in parallel
When connecting using a convenient SRV connection string (mongodb+srv://
) hostnames are obtained from an SRV dns lookup and some configuration options are obtained from a TXT dns query. Those DNS operations are now performed in parallel to reduce first-time connection latency.
Container and Kubernetes Awareness
The Node.js driver now keeps track of container metadata in the client.env.container
field of the handshake document.
If space allows, the following metadata will be included in client.env.container
:
env?: {
container?: {
orchestrator?: 'kubernetes' // if process.env.KUBERNETES_SERVICE_HOST is set
runtime?: 'docker' // if the '/.dockerenv' file exists
}
}
Note: If neither Kubernetes nor Docker is present, client.env
will not have the container
property.
Add property errorResponse
to MongoServerError
The MongoServer error maps keys from the error document returned by the server on to itself. There are some use cases where the original error document is desirable to obtain in isolation. So now, the mongoServerError.errorResponse
property stores a reference to the error document returned by the server.
Deprecated unused CloseOptions
interface
The CloseOptions
interface was unintentionally made public and was only intended for use in the driver's internals. Due to recent refactoring (NODE-5915), this interface is no longer used in the driver. Since it was marked public, out of an abundance of caution we will not be removing it outside of a major version, but we have deprecated it and will be removing it in the next major version.
Features
- NODE-5968: container and Kubernetes awareness in client metadata (#4005) (28b7040)
- NODE-5988: Provide access to raw results doc on MongoServerError (#4016) (c023242)
- NODE-6008: deprecate CloseOptions interface (#4030) (f6cd8d9)
Bug Fixes
- NODE-5636: generate _ids using pkFactory in bulk write operations (#4025) (fbb5059)
- NODE-5981: read preference not applied to commands properly (#4010) (937c9c8)
-
NODE-5985: throw Nodejs' certificate expired error when TLS fails to connect instead of
CERT_HAS_EXPIRED
(#4014) (057c223) -
NODE-5993: memory leak in the
Connection
class (#4022) (69de253)
Performance Improvements
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.