The official MongoDB Node.js driver
APACHE-2.0 License
Bot releases are hidden (Show)
The MongoDB Node.js team is pleased to announce version 3.3.4 of the driver
This release primary consists of improvements to the "unified topology". In particular, a regression with interaction between the connection pool and topology could result in servers which "go away" (due to network error, for example) would not return, resulting in a MongoTimeoutError
.
The MongoDB Node.js team is pleased to announce version 3.3.0 of the driver
This latest release brings support for features in the newly released MongoDB v4.2:
$merge
operatorThe Driver has supported connecting to a cluster using an SRV record since version 3.0. Prior to now, we would only resolve the SRV record when initially connecting. This was fine for single replica sets, as the driver is able to discover new members added after initial connect from any member of a replica set. However, in a sharded deployment, individual mongos processes do not have an awareness of each other. This means that if the deployment changes in a shared cluster, the driver would have no way of knowing without disconnecting and connecting with a new client.
Starting in 3.3, if a driver connects to a sharded cluster with an SRV record, we will now periodically check that SRV record for any changes in the deployment, and update the client-side connections accordingly.
**NOTE: This feature is only available when starting a client with { useUnifiedTopology: true }
**
The driver now has support for MongoDB Client-Side Encryption. This requires installing the mongodb-client-encryption
npm package in your project.
mongodb-core
into node-mongodb-native
Up until this release, the mongodb
driver has consisted of two components:
mongodb-core
: The low-level engine of the driver.node-mongodb-native
: The API layer of the driver, published as mongodb
Over time, this separation has done more harm than good, and has led to increased development time for repairing bugs and implementing new features. Starting in the 3.3 release of mongodb
, we have merged mongodb-core
into node-mongodb-native
, removing this barrier to development.
The MongoDB Node.js team is pleased to announce version 3.2.1 of the driver.
Due to a publishing snafu v3.2.1 was immediately published without a proper v3.2.0 release
The Topology
class no longer uses a callback store, instead relying on a server selection loop for operation execution. This means failed operations will fail faster, with more accurate stack traces and specifics about the failure. It generally makes it much easier to reason about what the driver is doing each time an operation is executed.
You can enable it with the useUnifiedTopology
feature flag passed to your MongoClient
constructor, like so:
const client = MongoClient('mongodb://localhost:27017', { useUnifiedTopology: true });
This topology layer will replace the existing topologies in a breaking 4.x release later this year, so we strongly encourage our users to try it out as soon as possible.
A call to withTransaction
begins a new transaction, executes the provided function, and then attempts to commit the transaction. The function passed to withTransaction
must take a session
parameter, and this session must be passed to all methods within the function. If some error is encountered, it will attempt to re-commit the transaction before ultimately failing back to the user after aborting the transaction.
NOTE: A mentioned, the passed in function MAY be retried multiple times, please keep this in mind when executing non-database operations within the function.
Here’s an example of it in action:
const client = new MongoClient();
await client.connect();
const session = client.startSession();
// NOTE: the `withTransaction` method only supports functions that return a `Promise`
try {
await session.withTransaction(async function(session) {
const coll = client.db('foo').collection('coll');
await coll.insertOne({ a: 42 }, { session });
});
} catch (err) {
// transaction failed after attempted retry
console.dir({ err });
}
client.connect().then(async function() {
const collection = client.db(‘test’).collection(‘asyncIterators’);
const cursor = collection.find();
for await(const doc of cursor) {
console.log(item);
}
});
find()
.