Skip to content

Commit 3b9852d

Browse files
committed
RUST-717 Send hint as part of deletes array in delete operation
1 parent 1eebf3e commit 3b9852d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/operation/delete/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
collation::Collation,
99
error::{convert_bulk_errors, Result},
1010
operation::{append_options, Operation, Retryability, WriteResponseBody},
11-
options::{DeleteOptions, WriteConcern},
11+
options::{DeleteOptions, Hint, WriteConcern},
1212
results::DeleteResult,
1313
};
1414

@@ -19,6 +19,7 @@ pub(crate) struct Delete {
1919
limit: u32,
2020
options: Option<DeleteOptions>,
2121
collation: Option<Collation>,
22+
hint: Option<Hint>,
2223
}
2324

2425
impl Delete {
@@ -46,6 +47,7 @@ impl Delete {
4647
filter,
4748
limit: limit.unwrap_or(0), // 0 = no limit
4849
collation: options.as_mut().and_then(|opts| opts.collation.take()),
50+
hint: options.as_mut().and_then(|opts| opts.hint.take()),
4951
options,
5052
}
5153
}
@@ -65,6 +67,10 @@ impl Operation for Delete {
6567
delete.insert("collation", bson::to_bson(&collation)?);
6668
}
6769

70+
if let Some(ref hint) = self.hint {
71+
delete.insert("hint", bson::to_bson(&hint)?);
72+
}
73+
6874
let mut body = doc! {
6975
Self::NAME: self.ns.coll.clone(),
7076
"deletes": [delete],

src/test/coll.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,15 @@ async fn delete_hint_test(options: Option<DeleteOptions>, name: &str) {
611611
let events = client.get_command_started_events(&["delete"]);
612612
assert_eq!(events.len(), 1);
613613

614-
let event_hint = events[0].command.get("hint").cloned();
614+
let event_hint = events[0].command.get_array("deletes").unwrap()[0]
615+
.as_document()
616+
.unwrap()
617+
.get("hint");
615618
let expected_hint = match options {
616619
Some(options) => options.hint.map(|hint| hint.to_bson()),
617620
None => None,
618621
};
619-
assert_eq!(event_hint, expected_hint);
622+
assert_eq!(event_hint, expected_hint.as_ref());
620623
}
621624

622625
#[cfg_attr(feature = "tokio-runtime", tokio::test)]

0 commit comments

Comments
 (0)