Uploaded image for project: 'Rust Driver'
  1. Rust Driver
  2. RUST-796

ClientSession cannot be reborrowed while iterating a cursor

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.0.0-beta
    • Affects Version/s: 2.0.0-alpha.1
    • Component/s: None
    • Labels:
      None

      Currently, the session used by a SessionCursorHandle cannot be reborrowed within the while let loop that iterates over the cursor. This makes using cursors with sessions pretty clunky.

      repro:

       let mut cursor = coll.find_with_session(doc! {}, None, &mut session).await?
      // cursor does not retain the reference, so it can be used here
      coll.run_command_with_session(doc! { "ping": 1 }, None, &mut session).await?;
      
      while let Some(doc) = cursor.with_session(&mut_session).next().await? {
          println!("{}", doc?);
          // following line errors saying the session is already borrowed
          coll.run_command_with_session(doc! { "ping": 1 }, None, &mut session).await?;
      }

            Assignee:
            patrick.freed@mongodb.com Patrick Freed
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: