6.16.0 (2025-04-21)
The MongoDB Node.js team is pleased to announce version 6.16.0 of the mongodb
package!
Release Notes
distinct commands now support an index hint
The Collection.distinct()
method now supports an optional hint
, which can be used to tell the server which index to use for the command:
// providing an index description
await collection.distinct('my-key', {
hint: { 'my-key': 1 }
});
// providing an index name
await collection.distinct('my-key', {
hint: 'my-key'
});
This requires server 7.1+.
Driver support for servers <=4.0 deprecated
Warning
Node driver support for server 4.0 will be removed in an upcoming minor release. Reference: MongoDB Software Lifecycle Schedules.
Fix processing of multiple messages within one network data chunk
During elections, or other scenarios where the server is pushing multiple topology updates to the driver in a short period of time, a bug in the driver's socket code led to backlog of topology updates that would remain in the buffer until another heartbeat arrived from the server. This could lead to delays in the driver recovering from an election and/or an increase in MongoServerSelectionErrors.
Now, all messages in the current buffer are returned to the driver leading to faster processing times.
Huge thank you to @andreim-brd for sharing a self-contained reproduction that proved to be instrumental in the identification of the underlying issue!
FindCursor.rewind() throws documents?.clear() is not a function
errors in certain scenarios
In certain scenarios where limit and batchSize are both set on a FindCursor, an internal driver optimization intended to prevent unnecessary requests to the server when the driver knows the cursor is exhausted would prevent the cursor from being rewound. This issue has been resolved.
Features
- NODE-6494: add support for
hint
on distinct commands (#4487) (40d0e87) - NODE-6515: deprecate driver support for server 4.0 (#4517) (4c1a8a7)
Bug Fixes
- NODE-6630: read all messages in buffer when chunk arrives (#4512) (8c86e30)
- NODE-6878: documents.clear() throws a TypeError after cursor is rewound (#4488) (a1fffeb)
Documentation
We invite you to try the mongodb
library immediately, and report any issues to the NODE project.