v6.4.0
版本发布时间: 2024-03-01 03:59:28
mongodb/node-mongodb-native最新发布版本:v6.9.0(2024-09-13 01:12:41)
6.4.0 (2024-02-29)
The MongoDB Node.js team is pleased to announce version 6.4.0 of the mongodb
package!
Release Notes
Server selection will use a different Mongos on retry
When retrying reads or writes on a sharded cluster, the driver will attempt to select a different mongos for the retry if multiple are present. This should heuristically avoid encountering the original error that caused the need to retry the operation.
Caching AWS credentials provider per client
Instead of creating a new AWS provider for each authentication, we cache the AWS credentials provider per client to prevent overwhelming the auth endpoint and ensure that cached credentials are not shared with other clients.
BSON upgraded to ^6.4.0
BSON has had a number of performance increases in the last two releases (6.3.0 and 6.4.0). Small basic latin (ASCII) only strings, small memory allocations (ObjectId and Decimal128) and numeric parsing operations (int32, doubles, and longs) have all had optimizations applied to them.
For details check out the release notes here: BSON 6.3.0 and BSON 6.4.0 :racehorse:
ExceededTimeLimit was made a retryable reads error
Read operations will be retried after receiving an error with the ExceededTimeLimit
label.
Fixed unresolved request issue in KMS requester
Internal to the field-level encryption machinery is a helper that opens a TLS socket to the KMS provider endpoint and submits a KMS request. The code neglected to add a 'close'
event listener to the socket, which had the potential to improperly leave the promise pending indefinitely if no error was encountered.
The base64 padding is now preserved in the saslContinue command
The authentication was rejected by the saslContinue command from mongosh due to missing "=" padding from the client. We fixed the way we parse payload to preserve trailing "="s.
countDocuments
now types the filter using the collection Schema
Previously, countDocuments
had a weakly typed Document
type for the filter allowing any JS object as input. The filter is now typed as Filter<Schema>
to enable autocompletion, and, hopefully, catch minor bugs.
Thank you to @pashok88895 for contributing to this improvement.
The type error with $addToSet
in bulkWrite
was fixed
Previously the following code sample would show a type error:
interface IndexSingatureTestDocument extends Document {
readonly myId: number;
readonly mySet: number[];
}
const indexSingatureCollection = undefined as unknown as Collection<IndexSingatureTestDocument>;
indexSingatureCollection.bulkWrite([
{
updateOne: {
filter: { myId: 0 },
update: {
$addToSet: { mySet: 0 } // The type error! Type 'number' is not assignable to type 'never'.
}
}
}
]);
It happened because the driver's Document
type falls back to any
, and internally we could not distinguish whether or not this assignment was intentional and should be allowed.
After this change, users can extend their types from Document
/any
, or use properties of any
type and we skip the $addToSet
validation in those cases.
Fixed heartbeat duration including socket creation
The ServerHeartbeatSucceeded and ServerHeartbeatFailed event have a duration property that represents the time it took to perform the hello
handshake with MongoDB. The Monitor responsible for issuing heartbeats mistakenly included the time it took to create the socket in this field, which inflates the value with the time it takes to perform a DNS lookup, TCP, and TLS handshakes.
Errors on cursor transform streams are now properly propagated.
These were previously swallowed and now will be emitted on the error
event:
const transform = new Transform({
transform(data, encoding, callback) {
callback(null, data);
},
});
const stream = db.collection('tests').find().sort({ studentId: -1 }).stream({ transform });
stream.on('error', err => {
// The error will properly be emitted here.
});
The AWS token is now optional
Users may provide an AWS_SESSION_TOKEN
as a client option or AWS configuration in addition to a username and password. But if the token is not provided, the driver won't throw an exception and let AWS SDK handle the request.
Features
- NODE-3449: Add serverConnectionId to Command Monitoring Spec (735f7aa)
- NODE-3470: retry selects another mongos (#3963) (84959ee)
- NODE-3689: require hello command for connection handshake to use OP_MSG disallowing OP_QUERY (#3938) (ce7df0f)
- NODE-5717: make ExceededTimeLimit retryable reads error (#3947) (106ab09)
- NODE-5939: Implement 6.x: cache the AWS credentials provider in the MONGODB-AWS auth logic (#3991) (e0a37e5)
-
NODE-5978: upgrade BSON to
^6.4.0
(#4007) (90f2f70)
Bug Fixes
- NODE-5127: implement reject kmsRequest on server close (#3964) (568e05f)
- NODE-5609: node driver omits base64 padding in sasl-continue command (#3975) (b7d28d3)
- NODE-5765: change type for countDocuments (#3932) (22cae0f)
- NODE-5791: type error with $addToSet in bulkWrite (#3953) (b93d405)
- NODE-5840: heartbeat duration includes socket creation (#3973) (a42039b)
- NODE-5901: propagate errors to transformed stream in cursor (#3985) (ecfc615)
- NODE-5944: make AWS session token optional (#4002) (f26de76)
Performance Improvements
- NODE-5771: improve new connection (#3948) (a4776cf)
- NODE-5928: consolidate signal use and abort promise wrap (#3992) (38742c2)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.