Skip to content

RUST-2191 Aggregation is losing type after session #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
barvirm opened this issue Mar 26, 2025 · 1 comment
Open

RUST-2191 Aggregation is losing type after session #526

barvirm opened this issue Mar 26, 2025 · 1 comment
Assignees
Labels
tracked-in-jira Ticket filed in Mongo's Jira system

Comments

@barvirm
Copy link
Contributor

barvirm commented Mar 26, 2025

Aggregation is losing type after session.

Here is an example of what I mean by losing type.

use mongodb::bson::{doc, Document};
use mongodb::bson::oid::ObjectId;
use mongodb::{ClientSession, Collection, SessionCursor, Client};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct Record {
    #[serde(rename = "_id")]
    id: ObjectId,
    foobar: i32,
}

async fn main() {
    let client = Client::with_uri_str("i_dont_care").await.unwrap();
    let collection: Collection<Record> = client.database("db").collection("collection");
    
    let id = ObjectId::default();
    let pipeline = vec![doc!{ "_id": id }];
    let aggregation =  collection.aggregate(pipeline);
    
    let typed_aggregation = aggregation.with_type::<Record>();
    // Correct type 
    // let records: Cursor<Record> = typed_aggregation.await.unwrap();
    
    
    let mut session = client.start_session().await.unwrap();
    // We lose type from original aggregation and get SessionCursor<Document>
    // Shoudn't this be SessionCursor<Record> based on the previous type of PhantomData<Record> in Aggregation??
    let with_session: SessionCursor<Document> = typed_aggregation.session(session).await?;
}
@abr-egn
Copy link
Contributor

abr-egn commented Mar 31, 2025

Thanks for the report! This looks like a simple oversight on our part - I'll get a bugfix for this out shortly. In the meantime, you can work around this by calling with_type after session rather than before.

@abr-egn abr-egn changed the title Aggregation is losing type after session RUST-2191 Aggregation is losing type after session Mar 31, 2025
@abr-egn abr-egn added the tracked-in-jira Ticket filed in Mongo's Jira system label Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

No branches or pull requests

2 participants