Skip to content

Commit 60e57fa

Browse files
authored
RUST-1215/RUST-1145/RUST-1070 Add comment option to the estimatedDocumentCountOptions struct, let option to CRUD (#680)
Add comment option to the estimatedDocumentCountOptions struct and let (let_vars) option to CRUD operations, skip tests related to unimplemented aggregate $out and $merge feature
1 parent 0ee2619 commit 60e57fa

File tree

120 files changed

+15813
-2770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+15813
-2770
lines changed

src/coll/options.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ pub struct UpdateOptions {
211211

212212
/// The write concern for the operation.
213213
pub write_concern: Option<WriteConcern>,
214+
215+
/// Map of parameter names and values. Values must be constant or closed
216+
/// expressions that do not reference document fields. Parameters can then be
217+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
218+
///
219+
/// Only available in MongoDB 5.0+.
220+
#[serde(rename = "let")]
221+
pub let_vars: Option<Document>,
214222
}
215223

216224
impl UpdateOptions {
@@ -221,6 +229,7 @@ impl UpdateOptions {
221229
hint: options.hint,
222230
write_concern: options.write_concern,
223231
collation: options.collation,
232+
let_vars: options.let_vars,
224233
..Default::default()
225234
}
226235
}
@@ -253,6 +262,14 @@ pub struct ReplaceOptions {
253262

254263
/// The write concern for the operation.
255264
pub write_concern: Option<WriteConcern>,
265+
266+
/// Map of parameter names and values. Values must be constant or closed
267+
/// expressions that do not reference document fields. Parameters can then be
268+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
269+
///
270+
/// Only available in MongoDB 5.0+.
271+
#[serde(rename = "let")]
272+
pub let_vars: Option<Document>,
256273
}
257274

258275
/// Specifies the options to a
@@ -276,6 +293,14 @@ pub struct DeleteOptions {
276293
/// The index to use for the operation.
277294
/// Only available in MongoDB 4.4+.
278295
pub hint: Option<Hint>,
296+
297+
/// Map of parameter names and values. Values must be constant or closed
298+
/// expressions that do not reference document fields. Parameters can then be
299+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
300+
///
301+
/// Only available in MongoDB 5.0+.
302+
#[serde(rename = "let")]
303+
pub let_vars: Option<Document>,
279304
}
280305

281306
/// Specifies the options to a
@@ -310,6 +335,14 @@ pub struct FindOneAndDeleteOptions {
310335
/// The index to use for the operation.
311336
/// Only available in MongoDB 4.4+.
312337
pub hint: Option<Hint>,
338+
339+
/// Map of parameter names and values. Values must be constant or closed
340+
/// expressions that do not reference document fields. Parameters can then be
341+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
342+
///
343+
/// Only available in MongoDB 5.0+.
344+
#[serde(rename = "let")]
345+
pub let_vars: Option<Document>,
313346
}
314347

315348
/// Specifies the options to a
@@ -353,6 +386,14 @@ pub struct FindOneAndReplaceOptions {
353386
/// The index to use for the operation.
354387
/// Only available in MongoDB 4.4+.
355388
pub hint: Option<Hint>,
389+
390+
/// Map of parameter names and values. Values must be constant or closed
391+
/// expressions that do not reference document fields. Parameters can then be
392+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
393+
///
394+
/// Only available in MongoDB 5.0+.
395+
#[serde(rename = "let")]
396+
pub let_vars: Option<Document>,
356397
}
357398

358399
/// Specifies the options to a
@@ -402,6 +443,14 @@ pub struct FindOneAndUpdateOptions {
402443
/// The index to use for the operation.
403444
/// Only available in MongoDB 4.4+.
404445
pub hint: Option<Hint>,
446+
447+
/// Map of parameter names and values. Values must be constant or closed
448+
/// expressions that do not reference document fields. Parameters can then be
449+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
450+
///
451+
/// Only available in MongoDB 5.0+.
452+
#[serde(rename = "let")]
453+
pub let_vars: Option<Document>,
405454
}
406455

407456
/// Specifies the options to a [`Collection::aggregate`](../struct.Collection.html#method.aggregate)
@@ -574,6 +623,12 @@ pub struct EstimatedDocumentCountOptions {
574623
/// The level of the read concern.
575624
#[serde(skip_serializing)]
576625
pub read_concern: Option<ReadConcern>,
626+
627+
/// Tags the query with an arbitrary BSON object to help trace the operation through the
628+
/// database profiler, currentOp and logs.
629+
///
630+
/// This option is only available on server versions 4.4+.
631+
pub comment: Option<Bson>,
577632
}
578633

579634
/// Specifies the options to a [`Collection::distinct`](../struct.Collection.html#method.distinct)
@@ -720,6 +775,14 @@ pub struct FindOptions {
720775
/// See the [documentation](https://www.mongodb.com/docs/manual/reference/collation/) for more
721776
/// information on how to use this option.
722777
pub collation: Option<Collation>,
778+
779+
/// Map of parameter names and values. Values must be constant or closed
780+
/// expressions that do not reference document fields. Parameters can then be
781+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
782+
///
783+
/// Only available in MongoDB 5.0+.
784+
#[serde(rename = "let")]
785+
pub let_vars: Option<Document>,
723786
}
724787

725788
impl From<FindOneOptions> for FindOptions {
@@ -746,6 +809,7 @@ impl From<FindOneOptions> for FindOptions {
746809
max_await_time: None,
747810
no_cursor_timeout: None,
748811
sort: options.sort,
812+
let_vars: options.let_vars,
749813
}
750814
}
751815
}
@@ -834,6 +898,14 @@ pub struct FindOneOptions {
834898

835899
/// The order of the documents for the purposes of the operation.
836900
pub sort: Option<Document>,
901+
902+
/// Map of parameter names and values. Values must be constant or closed
903+
/// expressions that do not reference document fields. Parameters can then be
904+
/// accessed as variables in an aggregate expression context (e.g. "$$var").
905+
///
906+
/// Only available in MongoDB 5.0+.
907+
#[serde(rename = "let")]
908+
pub let_vars: Option<Document>,
837909
}
838910

839911
/// Specifies the options to a

src/operation/find_and_modify/options.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ pub(super) struct FindAndModifyOptions {
7272

7373
#[builder(default)]
7474
pub(crate) hint: Option<Hint>,
75+
76+
#[builder(default)]
77+
#[serde(rename = "let")]
78+
pub(crate) let_vars: Option<Document>,
7579
}
7680

7781
impl FindAndModifyOptions {
@@ -88,6 +92,7 @@ impl FindAndModifyOptions {
8892
modify_opts.sort = opts.sort;
8993
modify_opts.write_concern = opts.write_concern;
9094
modify_opts.hint = opts.hint;
95+
modify_opts.let_vars = opts.let_vars;
9196
modify_opts
9297
}
9398

@@ -109,6 +114,7 @@ impl FindAndModifyOptions {
109114
modify_opts.upsert = opts.upsert;
110115
modify_opts.write_concern = opts.write_concern;
111116
modify_opts.hint = opts.hint;
117+
modify_opts.let_vars = opts.let_vars;
112118

113119
modify_opts
114120
}
@@ -131,6 +137,7 @@ impl FindAndModifyOptions {
131137
modify_opts.upsert = opts.upsert;
132138
modify_opts.write_concern = opts.write_concern;
133139
modify_opts.hint = opts.hint;
140+
modify_opts.let_vars = opts.let_vars;
134141

135142
modify_opts
136143
}

src/operation/update/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ impl Operation for Update {
9797
body.insert("writeConcern", bson::to_bson(write_concern)?);
9898
}
9999
}
100+
101+
if let Some(ref let_vars) = options.let_vars {
102+
body.insert("let", let_vars);
103+
}
100104
};
101105

102106
if let Some(multi) = self.multi {

src/test/spec/crud.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ fn test_predicate(test: &TestCase) -> bool {
1818
// The Rust driver doesn't support unacknowledged writes.
1919
let lower = test.description.to_lowercase();
2020

21-
// TODO: RUST-1071, RUST-1215: unskip comment tests
22-
!lower.contains("unacknowledged") && !lower.contains("comment")
21+
!lower.contains("unacknowledged")
22+
// TODO: RUST-1071: unskip comment tests
23+
&& (!lower.contains("comment")
24+
|| lower.contains("estimateddocumentcount"))
25+
// TODO: RUST-663: unskip aggregate $out and $merge tests
26+
&& !(lower.contains("aggregate with $out includes read preference for 5.0+ server"))
27+
&& !(lower.contains("aggregate with $out omits read preference for pre-5.0 server"))
28+
&& !(lower.contains("aggregate with $merge includes read preference for 5.0+ server"))
29+
&& !(lower.contains("aggregate with $merge omits read preference for pre-5.0 server"))
2330
}

src/test/spec/json/crud/unified/aggregate-let.json

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -56,109 +56,6 @@
5656
"minServerVersion": "5.0"
5757
}
5858
],
59-
"operations": [
60-
{
61-
"name": "aggregate",
62-
"object": "collection0",
63-
"arguments": {
64-
"pipeline": [
65-
{
66-
"$match": {
67-
"$expr": {
68-
"$eq": [
69-
"$_id",
70-
"$$id"
71-
]
72-
}
73-
}
74-
},
75-
{
76-
"$project": {
77-
"_id": 0,
78-
"x": "$$x",
79-
"y": "$$y",
80-
"rand": "$$rand"
81-
}
82-
}
83-
],
84-
"let": {
85-
"id": 1,
86-
"x": "foo",
87-
"y": {
88-
"$literal": "bar"
89-
},
90-
"rand": {
91-
"$rand": {}
92-
}
93-
}
94-
},
95-
"expectResult": [
96-
{
97-
"x": "foo",
98-
"y": "bar",
99-
"rand": {
100-
"$$type": "double"
101-
}
102-
}
103-
]
104-
}
105-
],
106-
"expectEvents": [
107-
{
108-
"client": "client0",
109-
"events": [
110-
{
111-
"commandStartedEvent": {
112-
"command": {
113-
"aggregate": "coll0",
114-
"pipeline": [
115-
{
116-
"$match": {
117-
"$expr": {
118-
"$eq": [
119-
"$_id",
120-
"$$id"
121-
]
122-
}
123-
}
124-
},
125-
{
126-
"$project": {
127-
"_id": 0,
128-
"x": "$$x",
129-
"y": "$$y",
130-
"rand": "$$rand"
131-
}
132-
}
133-
],
134-
"let": {
135-
"id": 1,
136-
"x": "foo",
137-
"y": {
138-
"$literal": "bar"
139-
},
140-
"rand": {
141-
"$rand": {}
142-
}
143-
}
144-
}
145-
}
146-
}
147-
]
148-
}
149-
]
150-
},
151-
{
152-
"description": "Aggregate with let option and dollar-prefixed $literal value",
153-
"runOnRequirements": [
154-
{
155-
"minServerVersion": "5.0",
156-
"topologies": [
157-
"single",
158-
"replicaset"
159-
]
160-
}
161-
],
16259
"operations": [
16360
{
16461
"name": "aggregate",

src/test/spec/json/crud/unified/aggregate-let.yml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,9 @@ initialData: &initialData
2929
documents: [ ]
3030

3131
tests:
32-
# TODO: Once SERVER-57403 is resolved, this test can be removed in favor of
33-
# the "dollar-prefixed $literal value" test below.
3432
- description: "Aggregate with let option"
3533
runOnRequirements:
3634
- minServerVersion: "5.0"
37-
operations:
38-
- name: aggregate
39-
object: *collection0
40-
arguments:
41-
pipeline: &pipeline0
42-
# $match takes a query expression, so $expr is necessary to utilize
43-
# an aggregate expression context and access "let" variables.
44-
- $match: { $expr: { $eq: ["$_id", "$$id"] } }
45-
- $project: { _id: 0, x: "$$x", y: "$$y", rand: "$$rand" }
46-
# Values in "let" must be constant or closed expressions that do not
47-
# depend on document values. This test demonstrates a basic constant
48-
# value, a value wrapped with $literal (to avoid expression parsing),
49-
# and a closed expression (e.g. $rand).
50-
let: &let0
51-
id: 1
52-
x: foo
53-
y: { $literal: "bar" }
54-
rand: { $rand: {} }
55-
expectResult:
56-
- { x: "foo", y: "bar", rand: { $$type: "double" } }
57-
expectEvents:
58-
- client: *client0
59-
events:
60-
- commandStartedEvent:
61-
command:
62-
aggregate: *collection0Name
63-
pipeline: *pipeline0
64-
let: *let0
65-
66-
- description: "Aggregate with let option and dollar-prefixed $literal value"
67-
runOnRequirements:
68-
- minServerVersion: "5.0"
69-
# TODO: Remove topology restrictions once SERVER-57403 is resolved
70-
topologies: ["single", "replicaset"]
7135
operations:
7236
- name: aggregate
7337
object: *collection0

0 commit comments

Comments
 (0)