mongo-rust-driver icon indicating copy to clipboard operation
mongo-rust-driver copied to clipboard

RUST-1986 In 3.0.0, Collection::watch ignores the collection type parameter

Open cvijdea-bd opened this issue 1 year ago • 3 comments

It seems that in 3.0.0 the .watch() method always returns a stream of ChangeStreamEvent<mongodb::bson::Document>? This seems unfortunate given that in 2.8.2 watch respected the T param of Collection.

Also, I don't see this change mentioned in the update notes.

let coll: Collection<bson::RawDocumentBuf> = ...;
let mut stream = coll.watch().await?;

// ERROR: cannot convert from `std::option::Option<ChangeStreamEvent<mongodb::bson::Document>>` to `std::option::Option<ChangeStreamEvent<RawDocumentBuf>>`
let doc: Option<bson::RawDocumentBuf> = stream.next().await.transpose()?;

cvijdea-bd avatar Jul 02 '24 23:07 cvijdea-bd

Seems related to https://github.com/mongodb/mongo-rust-driver/issues/1153

cvijdea-bd avatar Jul 03 '24 00:07 cvijdea-bd

Oh I see now that there is also with_type on ChangeStream, so with this change it works as before:

let mut stream = coll.watch().await?.with_type::<ChangeStreamEvent<bson::RawDocumentBuf>>();

Then I guess this is the intended usage and this issue can be closed?

cvijdea-bd avatar Jul 03 '24 00:07 cvijdea-bd

This was an oversight and an unintended regression, we'll get a fix out shortly.

abr-egn avatar Jul 03 '24 17:07 abr-egn

We've just released version 3.0.1 that includes the fix for this.

abr-egn avatar Jul 09 '24 19:07 abr-egn