Releases: mongodb/mongo-rust-driver
v1.2.5
v2.1.0-beta
Description
The MongoDB Rust driver team is pleased to announce the v2.1.0-beta
release of the mongodb
crate. This release is a preview of the upcoming v2.1.0
release, which will be functionally the same but may contain fixes for any bugs identified in this beta. 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-beta
The exported version of bson
was updated to v2.1.0-beta
, 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-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)
Task
v2.0.2
v1.2.4
v2.0.1
The MongoDB Rust driver team is pleased to announce the 2.0.1
release of the mongodb
crate. This release includes a number of bug fixes:
- RUST-1046 Fix iteration of cursors when batchSize doesn't divide result size (#484, #482)
- Thanks for reporting @Weakky!
- RUST-1047 Ensure
TopologyClosedEvent
is the last SDAM event emitted (#485) - RUST-856 Fix race between server selection and server monitoring (#460)
- RUST-992 Enable auth tests for PLAIN and fix default authSource for such (#451)
v2.0.0
Description
The MongoDB Rust driver team is pleased to announce the v2.0.0
release of the mongodb
crate. This release is the culmination of several months of work, and it contains a number of new features, API improvements, and bug fixes. It is intended that this release will be very stable and that mongodb
will not have another major release for quite a long time.
Note that the new minimum supported Rust version (MSRV) is now 1.48.0.
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 tokio
to v1.x
(RUST-633)
The async runtime crate tokio
reached 1.0, and the driver's dependency on it was updated to 1.0 accordingly. This is a breaking change, since the driver will no longer work with earlier versions of tokio
.
Update dependency on bson
to v2.0.0
(RUST-1006)
The exported version of bson
was updated to v2.0.0
, which includes its own set of breaking changes. Check out the bson
release notes for more information.
Transactions support (RUST-90)
This release adds driver support for transactions, which are supported on replica sets in MongoDB 4.0+ and on sharded clusters in MongoDB 4.2+. Transactions require the use of a ClientSession
. 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.
Remove Document
as the default generic type for Collection
and Cursor
(RUST-735)
The generic parameter must now always be explicitly specified when referring to these types. Additionally, the Database::collection
and Database::collection_with_options
helpers now require a generic parameter to be specified as well. This was done to ease and promote the use of serde with the driver. As part of this, Database::collection_with_type
was removed as it was no longer necessary.
// old
let collection = db.collection("foo");
let typed_collection = db.collection_with_type::<MySerdeType>("foo");
struct C { cursor: Cursor }
struct Tc { cursor: Cursor<MySerdeType> }
// new
let collection = db.collection::<Document>("foo");
let typed_collection = db.collection::<MySerdeType>("foo");
struct C { cursor: Cursor<Document> }
struct Tc { cursor: Cursor<MySerdeType> }
Performance Improvements (RUST-518)
The driver was updated to leverage the new raw BSON serialization / deserialization functionality introduced in version 2.0.0
of the bson
crate, significantly improving the performance of reads and inserts (RUST-870, RUST-871). Additionally, many redundant clones were eliminated (RUST-536) and writes and reads to sockets are now buffered, yielding further performance improvements. Initial benchmarks indicate that large inserts and reads could execute in half the time or less in 2.0.0
than in 1.2.3
.
Index Management API (RUST-273)
The driver now exposes an API for creating, listing, and deleting indexes.
e.g.
let new_index = IndexModel::builder()
.keys(doc! { "x": 1 })
.options(IndexOptions::builder().unique(true).build())
.build();
let index_name = collection.create_index(new_index, None).await?.index_name;
let index_names = collection.list_index_names().await?;
assert!(index_names.contains(&index_name));
collection.drop_indexes(None).await?;
let index_names = collection.list_index_names().await?;
assert!(!index_names.contains(&index_name));
Versioned API support (#401)
MongoDB 5.0 introduced the Versioned API, and this release includes support for specifying it via the ClientOptions
.
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
.
Ensure API meets the Rust API Guidelines (RUST-765)
There is a community-maintained list of API guidelines that every stable Rust library is recommended to meet. The driver's current API wasn't conforming to these guidelines exactly, so a number of improvements were made to ensure that it does. Here we highlight a few of the more important changes made in this effort.
Various error API improvements (RUST-739, RUST-765)
Several improvements were made to the ErrorKind
enum according to the guidelines to provide a more consistent and stable API:
- The variants no longer wrap error types from unstable dependencies (C-STABLE)
- The variant are named more consistently (C-WORD-ORDER)
- Drop redundant
Error
suffix from each variant name
- Drop redundant
- Redundant error variants were consolidated
The total list of breaking changes is as follows:
- All error variants dropped the "Error" suffix (e.g.
ErrorKind::ServerSelectionError
=>ErrorKind::ServerSelection
) ErrorKind::ArgumentError
=>ErrorKind::InvalidArgument
ErrorKind::InvalidHostname
=> removed, consolidated intoErrorKind::InvalidArgument
ErrorKind::BsonDecode
=>ErrorKind::BsonDeserialization
ErrorKind::BsonEncode
=>ErrorKind::BsonSerialization
ErrorKind::ResponseError
=>ErrorKind::InvalidResponse
ErrorKind::DnsResolve(trust_dns_resolver::error::ResolveError)
=>ErrorKind::DnsResolve { message: String }
ErrorKind::InvalidDnsName
=> removed, consolidated intoErrorKind::DnsResolve
ErrorKind::NoDnsResults
=> removed, consolidated intoErrorKind::DnsResolve
ErrorKind::SrvLookupError
=> removed, consolidated intoErrorKind::DnsResolve
ErrorKind::TxtLookupError
=> removed, consolidated intoErrorKind::DnsResolve
ErrorKind::RustlsConfig(rustls::TLSerror)
=>ErrorKind::InvalidTlsConfig { message: String }
ErrorKind::ParseError
=> removed, consolidated intoErrorKind::InvalidTlsConfig
ErrorKind::WaitQueueTimeoutError
=> removed, thewait_queue_timeout
option is no longer supported (RUST-757)ErrorKind::OperationError
=> removed, consolidated intoErrorKind::InvalidResponse
andErrorKind::Internal
as appropriate
Stabilize or eliminate public dependencies on unstable types (C-STABLE, RUST-739)
The driver included types from a number of unstable (pre-1.0) dependencies in its public API, which presented a problem for the stability of the driver itself. tokio
was one such example of this, which is why when it went 1.0, the driver needed a 2.0 release. In an effort to ensure that the driver will no longer be subject to the semver breaks of unstable dependencies and can stay on 2.0 for the foreseeable future, the public dependencies on unstable types were removed altogether or stabilized such that they will always be present.
Here are the notable changes made as part of that:
- Cursor types now implement the
Stream
trait fromfutures-core
rather thanfutures
.futures-core
will be moving directly to1.0
next, whereasfutures
may have several semver-incompatible versions.- The 2.0 version of the driver will continue to depend on
futures-core 0.3
(current release), even afterfutures-core 1.0
is released and/or theStream
trait is included in the standard library. The cursor types will also implement each of theStream
traits fromfutures-core 1.0
andstd
as necessary, and users can depend on and import the one they wish to use. - It's possible no changes will need to be made in the driver to transition to
std::Stream
. See (rust-lang/futures-rs#2362)
ErrorKind
variants that wrapped unstable errors were removed or refactored (see above)- Introduced a
ResolverConfig
type that opaquely wraps atrust_dns_resolver::ResolverConfig
TlsOptions::into_rustls_config
was removed from the public API
Wrap Error::kind
in a Box
(RUST-742)
As an ergonomic improvement to the Error
type, the ErrorKind
field of Error
was updated to be wrapped in a Box
instead of an Arc
. This will allow you to get an owned ErrorKind
via the *
operator, which was previously impossible with the Arc
wrapper.
Accept impl Borrow<T>
in various CRUD methods (RUST-754)
Prior to this release, methods such as `Collection:...
v1.2.3
This release bumps a number of security related dependencies, one of which was causing compilation failures because it involved on a now-yanked transitive dependency. See #433 for more details.
The changes have been cherry-picked from commits on master contributed by @bugadani and @seanpianka (RUST-682 and RUST-970 respectively), thanks again to you both!
v2.0.0-beta.3
Description
The MongoDB Rust driver team is pleased to announce the v2.0.0-beta.3
release of the mongodb
crate. This is the fourth beta release in preparation for the 2.0.0
stable release, and it contains a few breaking changes, API improvements, and bug fixes that were not included in the previous betas. As with the previous betas, 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.3
The exported version of bson
was updated to v2.0.0-beta.3
, which includes its own set of changes. Check out the bson
release notes for more information.
Support for transactions on sharded topologies (#408)
Support for replica set transactions was introduced in a previous release, and this release expands that support to include sharded clusters! Note that sharded transactions are only supported in MongoDB 4.2+.
Direct BSON serialization / deserialization (#389, #406)
The driver was updated to leverage the new raw BSON serialization / deserialization functionality introduced in version 2.0.0-beta.3
of the bson
crate, significantly improving the performance of reads and inserts. Initial (rough) benchmarks indicate that large inserts and reads could execute in half the time (or less) than they used to.
Note that as part of this, the generic bound on Collection
is now required to be Sync
and Send
.
Versioned API support (#401)
MongoDB 5.0 introduced the Versioned API, and this release includes support for specifying it via the ClientOptions
.
Full Release Notes
New Features
- RUST-97 Support sharded transactions recovery token (#398)
- RUST-122 Support mongos pinning for sharded transactions (#383)
- RUST-732 Mark the versioned API options public. (#401)
- RUST-885 Support snapshot sessions (#390)
- RUST-666 Add options for timeseries collection creation (#381)
Improvements
- RUST-901 Bump
bson
dependency to2.0.0-beta.3
- RUST-870 Deserialize server response directly from raw BSON bytes (#389) (breaking)
- RUST-871 Serialize directly to BSON bytes in insert operations (#406)
- RUST-725 Use "hello" for handshake and heartbeat when an API version is declared (#380)
- RUST-768 Pass versioned API parameters to
getMore
and transaction-continuing commands. (#397) - RUST-836 Support the 'let' option for aggregate (#391)
- RUST-887 Use
HashMap::contains
inError::contains_label
(#386)
Bugfixes
- RUST-570 Improve compile times of the test suite (#412)
- RUST-793 Reduce size of returned futures (#417)
- RUST-945 Check that explicit sessions were created on the correct client (#405)
Tasks
- RUST-795 Update versioned api connection examples (#400)
- RUST-670 Expect unified test format operations to succeed (#388)
- RUST-665 Sync spec tests for field names with dots and dollars (#385)
- RUST-734 Document support for sharded transactions
- RUST-605 Update Versioned API Documentation
- RUST-873 Test redaction of replies to security-sensitive commands
- RUST-881 Run test suite with requireApiVersion 1
- RUST-895 Update documentation for Time Series
- RUST-944 Integration tests for observeSensitiveCommands
- RUST-749 Convert CRUD tests to unified format (#410)
- RUST-773 Update CMAP spec tests to prevent cross-test failpoint interference (#395)
- RUST-774 Allow tests to specify
backgroundThreadIntervalMS
to fix a race condition. (#396) - RUST-775 CMAP integration test waits for wrong event
- RUST-859 Improve bson_util function consistency (#411)
- RUST-905 Try reading the default server URI from a local file if $MONGODB_URI is unset (#409)
v2.0.0-beta.2
Description
The MongoDB Rust driver team is pleased to announce the v2.0.0-beta.2
release of the mongodb
crate. This is the third beta release in preparation for the 2.0.0
stable release, and it contains a few breaking changes, API improvements, and bug fixes that were not included in the first two betas. As with the previous betas, 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.2
The exported version of bson
was updated to v2.0.0-beta.2
, which includes its own set of changes. Check out the bson
release notes for more information.
Enable passing Option
to builder methods (RUST-858)
In a previous release, the builder methods were updated to accept non-Option
types, which came with a few ergonomic benefits. Unfortunately, this update made it difficult to pass in Option
s when needed. After receiving some feedback on this change from beta users, we decided to revert the builders back to the 1.x driver behavior, namely that the builder methods will now take Into<T>
, regardless of whether T
is an Option
or not.
Remove default generic type of Collection
(RUST-851)
In a previous release, the Database::collection
methods and Cursor
types were updated to no longer have Document
as their default generic types. It was intended that Collection
would be updated in the same manner, but the changes for it were accidentally omitted. This release fixes that, updating Collection
to no longer have a default generic type, meaning the generic type of Collection
must now always be specified.
Eliminate redundant clones (RUST-536)
A number of unnecessary clones of input documents and command responses were removed from the driver's operation execution logic, leading to significant performance improvements in certain situations. This is part of an ongoing effort to improve the driver's performance, with more changes to come in future releases.
Move trait bounds from Collection
to implementation blocks (RUST-852)
In prior releases, the generic type T
on Collection
had a few trait bounds (e.g. DeserializeOwned
and Serialize
). These bounds could become cumbersome in certain situations where only a subset of them was required, such as when performing a find
with a projection (i.e. a read-only type only needs to implement DeserializeOwned
). To resolve this issue, the trait bounds were moved from Collection
itself to the implementation blocks for the methods that require them, so the T
only needs to implement the trait requirements for the methods it's used in.
For example, if a collection is only used for insertion, T
only needs to implement Serialize
:
#[derive(Debug, Serialize)]
struct Foo {
name: String,
}
// wouldn't compile before because Foo isn't DeserializeOwned, but now compiles because `T` has no trait bounds
let collection = db.collection::<Foo>("foo");
// compiles because Foo is Serialize
collection.insert_one(Foo { name: "Foo".to_string() }, None).await?;
// doesn't compile since Foo isn't DeserializeOwned
collection.find_one(doc! {}, None).await?;
This also has the added benefit of allowing other structs and enums to contain Collection<T>
without also having to inherit the trait bounds, as Collection<T>
no longer has any.
Full Release Notes
Bugfixes
- RUST-851 Remove default generic type of
Collection
(breaking) - RUST-571 Fix race between SDAM and SRV Polling
- RUST-853 Connection pools must be created and eventually marked ready for any server if a direct connection is used
New Features
- RUST-662 Expose the Reason an Operation Fails Document Validation
Improvements
- RUST-858 Enable passing options to builder methods (breaking)
- RUST-536 Eliminate redundant clones
- RUST-852 Move trait bounds to implementation instead of Collection struct (thanks @univerz for suggesting!)
- RUST-695 Add test that ensures the error returned from being evicted from the WaitQueue is retryable
- RUST-777 Fix race condition in pool-clear-clears-waitqueue.yml test
- RUST-790 Rename
ServerApiVersion
variants toV1
,V2
, etc. - RUST-835 Bump maxWireVersion for MongoDB 5.0
- RUST-840 Buffer all reads and writes to sockets
- RUST-847 Redact Debug for Credential
- RUST-849 Remove extra fields from ConnectionPoolOptions included in events (breaking)
Tasks
- RUST-162 Test driver on ARM Linux platforms
- RUST-310 Rewrite URI options tests to use serde
- RUST-814 Test on newer Ubuntu version(s)
- RUST-820 Test against 5.0 servers
- RUST-35 Add integration tests for writeConcern using command monitoring
- RUST-652 Add script to run all linter tests
- RUST-810 Add test for security-sensitive command monitoring event redaction
v1.2.2
This release fixes the security issue identified in RUST-591 / RUST-847 (CVE-2021-20332). It is recommended that all users of the 1.x driver upgrade to this version to receive the fix. Note that this was also already fixed in v2.0.0-beta
.