Skip to content

RUST-2191 Aggregation is losing type after session #526

Open
@barvirm

Description

@barvirm

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?;
}

Metadata

Metadata

Assignees

Labels

tracked-in-jiraTicket filed in Mongo's Jira system

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions