github mongodb/mongo-rust-driver v2.0.0-beta.1

latest releases: v1.2.5, v2.1.0, v2.1.0-beta...
pre-release3 years ago

Description

The MongoDB Rust driver team is pleased to announce the v2.0.0-beta.1 release of the mongodb crate. This is the second beta release in preparation for the 2.0.0 stable release, and it contains a few breaking changes, new features, API improvements, and bug fixes that were not included in the first beta. As with the previous beta, we do not intend to make any further breaking changes before v2.0.0, but we may do so in another beta if any issues arise before then.

Highlighted changes

The following sections detail some of the more important changes included in this release. For a full list of changes, see the Full Release Notes section.

Update version of bson to v2.0.0-beta.1

The exported version of bson was updated to v2.0.0-beta.1, which includes its own set of breaking changes. Check out the bson release notes for more information.

Note: chrono and uuid public API components are now gated behind the "bson/chrono-0_4" and "bson/uuid-0_8" feature flags respectively.

Replica Set Transactions (RUST-90)

This release adds driver support the for replica set transactions, which are supported in MongoDB 4.0+. Transactions require the use of a ClientSession, which was introduced in a previous release. Each operation in the transaction must pass the ClientSession into it via the _with_session suffixed version of the operation. For more information and detailed examples, see the ClientSession documentation.

use mongodb::options::{Acknowledgment, ReadConcern, TransactionOptions};
use mongodb::{
    bson::{doc, Document},
    options::WriteConcern,
};
let mut session = client.start_session(None).await?;

let txn_options = TransactionOptions::builder()
    .write_concern(WriteConcern::builder().w(Acknowledgment::Majority).build())
    .read_concern(ReadConcern::majority())
    .build();

session.start_transaction(txn_options).await?;
collection
    .insert_one_with_session(doc! { "x": 1 }, None, &mut session)
    .await?;
collection
    .delete_one_with_session(doc! { "x": 2 }, None, &mut session)
    .await?;
session.commit_transaction().await?;

The "snapshot" read concern level was also introduced as part of this feature.

Reduce the default max_pool_size to 10 (RUST-823)

In prior versions of the driver, the default max_pool_size was 100, but this is likely far too high to be a default. For some background on the motivation, see here and here. Note that this is also in line with the defaults for r2d2 and bb8.

Full Release Notes

New features

  • RUST-90 Implement Replica Set transactions
  • RUST-824 Add Snapshot variant to ReadConcernLevel enum

Improvements

  • RUST-811 Add feature flags for chrono and uuid interop in bson (breaking)
  • RUST-823 Reduce the default max_pool_size to 10 (breaking)
  • RUST-830 Consolidate error labels to Error::labels (breaking)
  • minor: update semver to 1.0 (thanks @dtolnay!)

Don't miss a new mongo-rust-driver release

NewReleases is sending notifications on new releases.