Skip to content

Commit 30122b7

Browse files
authored
RUST-1364 Collapse comment and comment_bson (#1070)
1 parent 131d53a commit 30122b7

File tree

4 files changed

+11
-62
lines changed

4 files changed

+11
-62
lines changed

src/action/find.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ impl<'a, T: Send + Sync, Session> Find<'a, T, Session> {
8686
allow_disk_use: bool,
8787
allow_partial_results: bool,
8888
batch_size: u32,
89-
comment: String,
90-
comment_bson: Bson,
89+
comment: Bson,
9190
cursor_type: CursorType,
9291
hint: Hint,
9392
limit: i64,
@@ -168,8 +167,7 @@ impl<'a, T: Send + Sync> FindOne<'a, T> {
168167
option_setters! { options: FindOneOptions;
169168
allow_partial_results: bool,
170169
collation: Collation,
171-
comment: String,
172-
comment_bson: Bson,
170+
comment: Bson,
173171
hint: Hint,
174172
max: Document,
175173
max_scan: u64,

src/coll/options.rs

+5-27
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ pub struct AggregateOptions {
544544
/// Tags the query with an arbitrary [`Bson`] value to help trace the operation through the
545545
/// database profiler, currentOp and logs.
546546
///
547-
/// This option is only supported on server versions 4.4+. Use the `comment` option on
548-
/// older server versions.
547+
/// For server versions less than 4.4, only a string value may be provided.
549548
pub comment: Option<Bson>,
550549

551550
/// The index to use for the operation.
@@ -767,22 +766,11 @@ pub struct FindOptions {
767766
#[serde(serialize_with = "serde_util::serialize_u32_option_as_i32")]
768767
pub batch_size: Option<u32>,
769768

770-
/// Tags the query with an arbitrary string to help trace the operation through the
771-
/// database profiler, currentOp and logs.
772-
///
773-
/// If both this option and `comment_bson` are specified, `comment_bson` will take precedence.
774-
// TODO RUST-1364: Update this field to be of type Option<Bson>
775-
#[serde(skip_serializing)]
776-
pub comment: Option<String>,
777-
778769
/// Tags the query with an arbitrary [`Bson`] value to help trace the operation through the
779770
/// database profiler, currentOp and logs.
780771
///
781-
/// This option is only supported on server versions 4.4+. Use the `comment` option on
782-
/// older server versions.
783-
// TODO RUST-1364: Remove this field
784-
#[serde(rename(serialize = "comment"))]
785-
pub comment_bson: Option<Bson>,
772+
/// For server versions less than 4.4, only a string value may be provided.
773+
pub comment: Option<Bson>,
786774

787775
/// The type of cursor to return.
788776
#[serde(skip)]
@@ -878,7 +866,6 @@ impl From<FindOneOptions> for FindOptions {
878866
allow_partial_results: options.allow_partial_results,
879867
collation: options.collation,
880868
comment: options.comment,
881-
comment_bson: options.comment_bson,
882869
hint: options.hint,
883870
max: options.max,
884871
max_scan: options.max_scan,
@@ -932,20 +919,11 @@ pub struct FindOneOptions {
932919
/// information on how to use this option.
933920
pub collation: Option<Collation>,
934921

935-
/// Tags the query with an arbitrary string value to help trace the operation through the
936-
/// database profiler, currentOp and logs.
937-
///
938-
/// If both this option and `comment_bson` are specified, `comment_bson` will take precedence.
939-
// TODO RUST-1364: Update this field to be of type Option<Bson>
940-
pub comment: Option<String>,
941-
942922
/// Tags the query with an arbitrary [`Bson`] value to help trace the operation through the
943923
/// database profiler, currentOp and logs.
944924
///
945-
/// This option is only supported on server versions 4.4+. Use the `comment` option on
946-
/// older server versions.
947-
// TODO RUST-1364: Remove this field
948-
pub comment_bson: Option<Bson>,
925+
/// For server versions less than 4.4, only a string value may be provided.
926+
pub comment: Option<Bson>,
949927

950928
/// The index to use for the operation.
951929
pub hint: Option<Hint>,

src/operation/find.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,7 @@ pub(crate) struct Find {
2222
}
2323

2424
impl Find {
25-
pub(crate) fn new(ns: Namespace, filter: Document, mut options: Option<FindOptions>) -> Self {
26-
if let Some(ref mut options) = options {
27-
if let Some(ref comment) = options.comment {
28-
if options.comment_bson.is_none() {
29-
options.comment_bson = Some(comment.clone().into());
30-
}
31-
}
32-
}
33-
25+
pub(crate) fn new(ns: Namespace, filter: Document, options: Option<FindOptions>) -> Self {
3426
Self {
3527
ns,
3628
filter,
@@ -108,9 +100,7 @@ impl OperationWithDefaults for Find {
108100
let comment = if description.max_wire_version.unwrap_or(0) < SERVER_4_4_0_WIRE_VERSION {
109101
None
110102
} else {
111-
self.options
112-
.as_ref()
113-
.and_then(|opts| opts.comment_bson.clone())
103+
self.options.as_ref().and_then(|opts| opts.comment.clone())
114104
};
115105

116106
Ok(CursorSpecification::new(

src/test/spec/unified_runner/operation.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -553,20 +553,13 @@ impl Find {
553553
) -> Result<TestCursor> {
554554
let collection = test_runner.get_collection(id).await;
555555

556-
let (comment, comment_bson) = match &self.comment {
557-
Some(Bson::String(string)) => (Some(string.clone()), None),
558-
Some(bson) => (None, Some(bson.clone())),
559-
None => (None, None),
560-
};
561-
562556
// `FindOptions` is constructed without the use of `..Default::default()` to enforce at
563557
// compile-time that any new fields added there need to be considered here.
564558
let options = FindOptions {
565559
allow_disk_use: self.allow_disk_use,
566560
allow_partial_results: self.allow_partial_results,
567561
batch_size: self.batch_size,
568-
comment,
569-
comment_bson,
562+
comment: self.comment.clone(),
570563
hint: self.hint.clone(),
571564
limit: self.limit,
572565
max: self.max.clone(),
@@ -1040,21 +1033,11 @@ impl<'de> Deserialize<'de> for FindOne {
10401033
#[derive(Deserialize)]
10411034
struct Helper {
10421035
filter: Option<Document>,
1043-
comment: Option<Bson>,
10441036
#[serde(flatten)]
10451037
options: FindOneOptions,
10461038
}
10471039

1048-
let mut helper = Helper::deserialize(deserializer)?;
1049-
match helper.comment {
1050-
Some(Bson::String(string)) => {
1051-
helper.options.comment = Some(string);
1052-
}
1053-
Some(bson) => {
1054-
helper.options.comment_bson = Some(bson);
1055-
}
1056-
_ => {}
1057-
}
1040+
let helper = Helper::deserialize(deserializer)?;
10581041

10591042
Ok(Self {
10601043
filter: helper.filter,

0 commit comments

Comments
 (0)