Releases: mongodb/mongo-rust-driver
v2.2.0-beta
Description
The MongoDB Rust driver team is pleased to announce the v2.2.0-beta release of the mongodb
crate.
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 below.
Change Streams (RUST-521, RUST-74, RUST-522, RUST-1149, RUST-523, RUST-1104)
This release adds support for Change Streams, which allow applications to access real-time data changes without the complexity and risk of tailing the oplog. Applications can use change streams to subscribe to all data changes on a single collection, a database, or an entire deployment, and immediately react to them.
let mut change_stream = coll.watch(None, None).await?;
let coll_ref = coll.clone();
task::spawn(async move {
coll_ref.insert_one(doc! { "x": 1 }, None).await;
});
while let Some(event) = change_stream.next().await.transpose()? {
println!("operation performed: {:?}, document: {:?}", event.operation_type, event.full_document);
// operation performed: Insert, document: Some(Document({"x": Int32(1)}))
}
Raw BSON Incorporation (RUST-1133, RUST-1175)
This release uses the new raw BSON types introduced in v2.2 of the bson
crate for internal operations, boosting performance in certain circumstances. It also allows for zero-copy deserialization when working with cursors via the new Cursor::deserialize_current
method:
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Cat<'a> {
#[serde(borrow)]
name: &'a str
}
let coll = db.collection::<Cat>("cat");
let mut cursor = coll.find(None, None).await?;
while cursor.advance().await? {
println!("{:?}", cursor.deserialize_current()?);
}
MSRV and Dependency Update (RUST-1192, RUST-1220)
This release updates the version of all dependencies used by the Rust driver to their most recent, which required an update of the MSRV to 1.51.
OpenSSL Support (RUST-1083)
This release adds optional support for using OpenSSL for TLS streams via the new openssl-tls
feature. Note that rustls
is still required as a dependency in this case to avoid breaking backwards compatibility; this will be removed in a future major version release.
Full Release Notes
New Features
- RUST-521 Implement naive streaming and resume token caching for change streams (#531)
- RUST-1133 Update driver to use the raw BSON API (#546)
- RUST-74 Add cluster_time to ChangeStreamEvent (#548)
- RUST-522 Implement resume functionality for change streams (#547)
- RUST-1149 Prose tests for change streams. (#561)
- RUST-523 Support change streams in unified spec tests (#564)
- RUST-1104 sync wrapper for the change stream API (#566)
- RUST-1106 Make the change streams API visible (#571)
- RUST-43 Add change streams examples for documentation (#572)
- RUST-1138 Add bson-serde_with feature flag (#580)
- RUST-1175 Support zero-copy deserialization from cursors (#579)
- RUST-995 Add tokio-sync feature flag (#578)
- RUST-1083 Add openssl as an optional TLS provider (#590)
Bugfixes
- minor: derive TypedBuilder for TimeseriesOptions (#557)
- minor: fix external crate links (#552)
- RUST-1163 Fix load balancer tests (#576)
- RUST-812 Reduce flakiness of in_window::load_balancing_test (#568)
- RUST-1163 Fix load balancer auth tests (#581)
Improvements
- RUST-1088 Always specify error labels at the top level (#553)
- RUST-894 Unskip write_error::details test on sharded clusters (#526)
- RUST-395 Log skipped tests (#523)
- RUST-1143 Bump max wire version to 15 (#573)
- RUST-1077 Update read/write concern document tests (#567)
- RUST-1173 Replace "Versioned API" references with "Stable API" (#585)
- RUST-1192 Bump MSRV to 1.49.0 (#584)
- RUST-1207 Bump zstd to v0.10 (#588) (thanks @moy2010!)
- RUST-1220 Bump outdated dependencies (#596)
- RUST-886 Use lossy UTF-8 decoding for responses to insert and update commands (#601)
- RUST-803 Conditionally use hello for monitoring (#600)
- RUST-1064 Retry on handshake failure (#598)
v2.1.0
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)
Task
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)