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

ClientSession cannot be reborrowed while iterating a cursor

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-alpha.1
    • Fix Version/s: 2.0.0-beta
    • Component/s: None
    • Security Level: Public
    • Labels:
      None

      Description

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: