Skip to content

v2.0.0-beta.2

Pre-release
Pre-release
Compare
Choose a tag to compare
@patrickfreed patrickfreed released this 25 Jun 21:10

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 Options 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 to V1, 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