Description
The MongoDB Rust driver team is pleased to announce the v2.1.0
release of the mongodb
crate. This release contains a number of new features, bug fixes, and improvements, most notably support for Atlas Serverless.
Highlighted changes
The following sections detail some of the more important breaking changes included in this release. For a full list of changes, see the Full Release Notes section below.
Update dependency on bson
to v2.1.0
The exported version of bson
was updated to v2.1.0
, which includes its own set of changes. Check out the bson
release notes for more information.
Support for Atlas Serverless (RUST-653, RUST-983)
This release introduces load balancer support to the Rust driver, which enables it to be used with Atlas Serverless. As part of that, the test suite of the driver was updated to include testing against live Atlas Serverless instances to ensure full compatibility.
Wire protocol compression (RUST-54)
This release adds optional support for compressing the messages sent between the driver and the server. The available compression algorithms are zstd, snappy, and zlib, and they can be enabled via the zstd-compression
, snappy-compression
, and zlib-compression
feature flags respectively. By default, none of the feature flags are enabled.
let mut options = ClientOptions::parse("mongodb://localhost:27017").await?;
// the server will select the algorithm it supports from the list provided by the driver
options.compressors = Some(vec![
Compressor::Snappy,
Compressor::Zlib {
level: Default::default(),
},
Compressor::Zstd {
level: Default::default(),
},
]);
let client = Client::with_options(options)?;
let resp = client
.database("admin")
.run_command(
doc! {
"ping": 1
},
None,
)
.await?;
println!("{}", resp);
Causal consistency (RUST-48)
This release adds driver support for causal consistency and enables it by default on all ClientSession
s. For more information on the guarantees provided by causal consistency, check out the MongoDB manual.
let options = SessionOptions::builder().causal_consistency(true).build();
let mut session = client.start_session(Some(options)).await?;
let coll_options = CollectionOptions::builder()
.read_concern(ReadConcern::majority())
.write_concern(WriteConcern::builder().w(Acknowledgment::Majority).build())
.build();
let collection = client
.database("foo")
.collection_with_options("bar", coll_options);
collection
.insert_one_with_session(doc! { "read": "me" }, None, &mut session)
.await?;
collection
.find_one_with_session(doc! { "read": "me" }, None, &mut session)
.await?
.expect("causal consistency guarantees we can read our own writes");
Full Release Notes
New Features
- RUST-653 Load Balancer Support (#415, #421, #422, #495, #446, #461, #469, #470, #465, #473, #477, #480, #495, #510)
- RUST-903 Serverless Testing (#494, #497, #505, #504)
- RUST-48 Causal consistency support (#493)
- RUST-54 Add support for reading and writing OP_COMPRESSED (#476)
- RUST-1048 Expose the default database from Client and ClientOptions (#488) (thanks @WindSoilder!)
- RUST-892 Implement
FromStr
forServerAddress
(#458)
Bugfixes
- RUST-1122 Fix x509 auth for pkcs8 keys and Atlas free tier (#532) (thanks for reporting @Zageron!)
- RUST-856 Fix race between server selection and server monitoring (#460)
- RUST-992 Fix default authSource for PLAIN authentication (#451)
- RUST-1037 secondaryPreferred read preference is not forwarded to mongos (#480)
- RUST-1046 Fix iteration of session cursors when batchSize doesn't divide result size (#483)
- RUST-1047 Ensure
TopologyClosedEvent
is the last SDAM event emitted (#485) - RUST-1060 Omit non-pub fields from
Debug
output ofClientOptions
(#512)
Improvements
- RUST-993 Implement
Clone
forCollection<T>
even whenT
isn'tClone
(#454) - RUST-949 Use SDAM monitoring in auth_error test
- RUST-1021 Use
ServerAddress::parse
for URI parsing (#471) - RUST-1032 Avoid redundant allocations in
Collection::clone_with_type
(#467) (thanks @PhotonQuantum!) - RUST-1076 Remove conditional definition of driver modules (#511)
- RUST-807 Disallow maxPoolSize=0 (#491)
- RUST-1027 Update maxWireVersion to 14 in support of 5.1 (#503)
- RUST-1076 Remove conditional module definitions (#511)