v2.0.0-alpha.1
Pre-releaseDescription
The MongoDB Rust driver team is pleased to announce the v2.0.0-alpha.1 release of the driver. This is the second alpha release in preparation for the 2.0 version of the driver, and it contains a number of breaking changes, new features, and bug fixes.
This release also contains all of the changes that were included in v1.2.0 but not in v2.0.0-alpha. Check out the release notes for v1.2.0 for more information.
Note: this release also updates the MSRV to 1.47
Release Notes
Breaking Changes
Document no longer the default generic type for Collection and Cursor (RUST-735)
The generic parameter must now always 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> }Improved Error Matching (RUST-679)
The error API was updated to allow for easier matching by removing the Arc wrapper around Error::kind. Instead, the Arc was moved into the cases that did not implement Clone.
// old
match e.kind.as_ref() {
ErrorKind::Io(e) => todo!(),
_ => todo!()
}
// new
match e.kind {
ErrorKind::Io(e) => todo!(),
_ => todo!()
}New Features
Improvements
- RUST-679 Simplify error API to ease pattern matching (breaking)
- RUST-719 Correct casing in
ServerTypevariants (breaking) - RUST-705 Switch from
err-derivetothiserror - RUST-658 Change
estimated_document_count()to use the$collStatsaggregation stage