Skip to content
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

RUST-1588: Add RunCursorCommand #912

Merged
merged 15 commits into from
Jul 19, 2023
17 changes: 11 additions & 6 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,23 @@ impl Database {
options: RunCursorCommandOptions,
session: &mut ClientSession,
) -> Result<SessionCursor<Document>> {
let mut selection_criteria = SelectionCriteria::ReadPreference(options.read_preference.clone().unwrap()).into();
match session.transaction.state {
TransactionState::Starting | TransactionState::InProgress => {
if command.contains_key("readConcern") {
return Err(ErrorKind::InvalidArgument {
message: "Cannot set read concern after starting a transaction".into(),
selection_criteria = match selection_criteria {
Some(selection_criteria) => Some(selection_criteria),
None => {
if let Some(ref options) = session.transaction.options {
options.selection_criteria.clone()
} else {
None
}
}
.into());
}
};
}
_ => {}
}
let rcc = RunCommand::new(self.name().to_string(), command, options.read_preference.clone(), None)?;
let rcc = RunCommand::new(self.name().to_string(), command, selection_criteria, None)?;
let rc_command = RunCursorCommand {
run_command: rcc,
options,
Expand Down
6 changes: 2 additions & 4 deletions src/db/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
bson::{Bson, Document},
concern::{ReadConcern, WriteConcern},
options::{Collation, CursorType},
selection_criteria::SelectionCriteria,
selection_criteria::{SelectionCriteria, ReadPreference},
serde_util,
};

Expand Down Expand Up @@ -332,7 +332,7 @@ pub struct RunCursorCommandOptions {
/// Optional string enum value, one of 'iteration' | 'cursorLifetime'.
pub timeout_mode: Option<TimeoutMode>,
/// The default read preference for operations.
pub read_preference: Option<SelectionCriteria>,
pub read_preference: Option<ReadPreference>,
/// Optional string enum value, one of 'tailable' | 'tailableAwait' | 'nonTailable'.
pub cursor_type: Option<CursorType>,
/// Number of documents to return per batch.
Expand All @@ -343,6 +343,4 @@ pub struct RunCursorCommandOptions {
/// Optional BSON value. Use this value to configure the comment option sent on subsequent
/// getMore commands.
pub comment: Option<Bson>,
/// The session to run this command with.
pub session: Option<String>,
}
2 changes: 1 addition & 1 deletion src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub(crate) use run_command::RunCommand;
pub(crate) use update::Update;

const SERVER_4_2_0_WIRE_VERSION: i32 = 8;
pub const SERVER_4_4_0_WIRE_VERSION: i32 = 9;
const SERVER_4_4_0_WIRE_VERSION: i32 = 9;

/// A trait modeling the behavior of a server side operation.
///
Expand Down