Skip to content

Commit 9884e19

Browse files
authored
Added support for let in operations (#900)
JAVA-4366
1 parent eeb2681 commit 9884e19

Some content is hidden

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

41 files changed

+3380
-136
lines changed

driver-core/src/main/com/mongodb/client/model/BulkWriteOptions.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.mongodb.lang.Nullable;
2020
import org.bson.BsonString;
2121
import org.bson.BsonValue;
22+
import org.bson.conversions.Bson;
2223

2324
/**
2425
* The options to apply to a bulk write.
@@ -29,6 +30,7 @@ public final class BulkWriteOptions {
2930
private boolean ordered = true;
3031
private Boolean bypassDocumentValidation;
3132
private BsonValue comment;
33+
private Bson variables;
3234

3335
/**
3436
* If true, then when a write fails, return without performing the remaining
@@ -117,12 +119,41 @@ public BulkWriteOptions comment(@Nullable final BsonValue comment) {
117119
return this;
118120
}
119121

122+
/**
123+
* Add top-level variables to the operation
124+
*
125+
* @return the top level variables if set or null.
126+
* @mongodb.server.release 5.0
127+
* @since 4.6
128+
*/
129+
@Nullable
130+
public Bson getLet() {
131+
return variables;
132+
}
133+
134+
/**
135+
* Add top-level variables for the operation
136+
*
137+
* <p>Allows for improved command readability by separating the variables from the query text.
138+
* The value of let will be passed to all update and delete, but not insert, commands.
139+
*
140+
* @param variables for the operation or null
141+
* @return this
142+
* @mongodb.server.release 5.0
143+
* @since 4.6
144+
*/
145+
public BulkWriteOptions let(@Nullable final Bson variables) {
146+
this.variables = variables;
147+
return this;
148+
}
149+
120150
@Override
121151
public String toString() {
122152
return "BulkWriteOptions{"
123153
+ "ordered=" + ordered
124154
+ ", bypassDocumentValidation=" + bypassDocumentValidation
125155
+ ", comment=" + comment
156+
+ ", let=" + variables
126157
+ '}';
127158
}
128159
}

driver-core/src/main/com/mongodb/client/model/DeleteOptions.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class DeleteOptions {
3333
private String hintString;
3434
private Collation collation;
3535
private BsonValue comment;
36+
private Bson variables;
3637

3738
/**
3839
* Returns the collation options
@@ -150,13 +151,44 @@ public DeleteOptions comment(@Nullable final BsonValue comment) {
150151
return this;
151152
}
152153

154+
/**
155+
* Add top-level variables to the operation
156+
*
157+
* <p>The value of let will be passed to all update and delete, but not insert, commands.
158+
*
159+
* @return the top level variables if set or null.
160+
* @mongodb.server.release 5.0
161+
* @since 4.6
162+
*/
163+
@Nullable
164+
public Bson getLet() {
165+
return variables;
166+
}
167+
168+
/**
169+
* Add top-level variables for the operation
170+
*
171+
* <p>Allows for improved command readability by separating the variables from the query text.
172+
* <p>For bulk operations use: {@link BulkWriteOptions#let(Bson)}
173+
*
174+
* @param variables for the operation or null
175+
* @return this
176+
* @mongodb.server.release 5.0
177+
* @since 4.6
178+
*/
179+
public DeleteOptions let(final Bson variables) {
180+
this.variables = variables;
181+
return this;
182+
}
183+
153184
@Override
154185
public String toString() {
155186
return "DeleteOptions{"
156187
+ "collation=" + collation
157188
+ ", hint=" + hint
158189
+ ", hintString='" + hintString + '\''
159190
+ ", comment=" + comment
191+
+ ", let=" + variables
160192
+ '}';
161193
}
162194
}

driver-core/src/main/com/mongodb/client/model/FindOneAndDeleteOptions.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class FindOneAndDeleteOptions {
4040
private Bson hint;
4141
private String hintString;
4242
private BsonValue comment;
43+
private Bson variables;
4344

4445
/**
4546
* Gets a document describing the fields to return for all matching documents.
@@ -226,6 +227,33 @@ public FindOneAndDeleteOptions comment(@Nullable final BsonValue comment) {
226227
return this;
227228
}
228229

230+
/**
231+
* Add top-level variables to the operation
232+
*
233+
* @return the top level variables if set or null.
234+
* @mongodb.server.release 5.0
235+
* @since 4.6
236+
*/
237+
@Nullable
238+
public Bson getLet() {
239+
return variables;
240+
}
241+
242+
/**
243+
* Add top-level variables for the operation
244+
*
245+
* <p>Allows for improved command readability by separating the variables from the query text.
246+
*
247+
* @param variables for the operation or null
248+
* @return this
249+
* @mongodb.server.release 5.0
250+
* @since 4.6
251+
*/
252+
public FindOneAndDeleteOptions let(final Bson variables) {
253+
this.variables = variables;
254+
return this;
255+
}
256+
229257
@Override
230258
public String toString() {
231259
return "FindOneAndDeleteOptions{"
@@ -236,6 +264,7 @@ public String toString() {
236264
+ ", hint=" + hint
237265
+ ", hintString='" + hintString + '\''
238266
+ ", comment=" + comment
267+
+ ", let=" + variables
239268
+ '}';
240269
}
241270
}

driver-core/src/main/com/mongodb/client/model/FindOneAndReplaceOptions.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class FindOneAndReplaceOptions {
4343
private Bson hint;
4444
private String hintString;
4545
private BsonValue comment;
46+
private Bson variables;
4647

4748
/**
4849
* Gets a document describing the fields to return for all matching documents.
@@ -288,6 +289,33 @@ public FindOneAndReplaceOptions comment(@Nullable final BsonValue comment) {
288289
return this;
289290
}
290291

292+
/**
293+
* Add top-level variables to the operation
294+
*
295+
* @return the top level variables if set or null.
296+
* @mongodb.server.release 5.0
297+
* @since 4.6
298+
*/
299+
@Nullable
300+
public Bson getLet() {
301+
return variables;
302+
}
303+
304+
/**
305+
* Add top-level variables for the operation
306+
*
307+
* <p>Allows for improved command readability by separating the variables from the query text.
308+
*
309+
* @param variables for the operation or null
310+
* @return this
311+
* @mongodb.server.release 5.0
312+
* @since 4.6
313+
*/
314+
public FindOneAndReplaceOptions let(final Bson variables) {
315+
this.variables = variables;
316+
return this;
317+
}
318+
291319
@Override
292320
public String toString() {
293321
return "FindOneAndReplaceOptions{"
@@ -301,6 +329,7 @@ public String toString() {
301329
+ ", hint=" + hint
302330
+ ", hintString" + hintString
303331
+ ", comment=" + comment
332+
+ ", let=" + variables
304333
+ '}';
305334
}
306335
}

driver-core/src/main/com/mongodb/client/model/FindOneAndUpdateOptions.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class FindOneAndUpdateOptions {
4545
private Bson hint;
4646
private String hintString;
4747
private BsonValue comment;
48+
private Bson variables;
4849

4950
/**
5051
* Gets a document describing the fields to return for all matching documents.
@@ -314,6 +315,33 @@ public FindOneAndUpdateOptions comment(@Nullable final BsonValue comment) {
314315
return this;
315316
}
316317

318+
/**
319+
* Add top-level variables to the operation
320+
*
321+
* @return the top level variables if set or null.
322+
* @mongodb.server.release 5.0
323+
* @since 4.6
324+
*/
325+
@Nullable
326+
public Bson getLet() {
327+
return variables;
328+
}
329+
330+
/**
331+
* Add top-level variables for the operation
332+
*
333+
* <p>Allows for improved command readability by separating the variables from the query text.
334+
*
335+
* @param variables for the operation or null
336+
* @return this
337+
* @mongodb.server.release 5.0
338+
* @since 4.6
339+
*/
340+
public FindOneAndUpdateOptions let(final Bson variables) {
341+
this.variables = variables;
342+
return this;
343+
}
344+
317345
@Override
318346
public String toString() {
319347
return "FindOneAndUpdateOptions{"
@@ -328,6 +356,7 @@ public String toString() {
328356
+ ", hint=" + hint
329357
+ ", hintString=" + hintString
330358
+ ", comment=" + comment
359+
+ ", let=" + variables
331360
+ '}';
332361
}
333362
}

driver-core/src/main/com/mongodb/client/model/ReplaceOptions.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ReplaceOptions {
3636
private Bson hint;
3737
private String hintString;
3838
private BsonValue comment;
39+
private Bson variables;
3940

4041
/**
4142
* Returns true if a new document should be inserted if there are no matches to the query filter. The default is false.
@@ -190,6 +191,35 @@ public ReplaceOptions comment(@Nullable final BsonValue comment) {
190191
this.comment = comment;
191192
return this;
192193
}
194+
/**
195+
* Add top-level variables to the operation
196+
*
197+
* <p>The value of let will be passed to all update and delete, but not insert, commands.
198+
*
199+
* @return the top level variables if set or null.
200+
* @mongodb.server.release 5.0
201+
* @since 4.6
202+
*/
203+
@Nullable
204+
public Bson getLet() {
205+
return variables;
206+
}
207+
208+
/**
209+
* Add top-level variables for the operation
210+
*
211+
* <p>Allows for improved command readability by separating the variables from the query text.
212+
* <p>For bulk operations use: {@link BulkWriteOptions#let(Bson)}
213+
*
214+
* @param variables for the operation or null
215+
* @return this
216+
* @mongodb.server.release 5.0
217+
* @since 4.6
218+
*/
219+
public ReplaceOptions let(final Bson variables) {
220+
this.variables = variables;
221+
return this;
222+
}
193223

194224
@Override
195225
public String toString() {
@@ -200,6 +230,7 @@ public String toString() {
200230
+ ", hint=" + hint
201231
+ ", hintString=" + hintString
202232
+ ", comment=" + comment
233+
+ ", let=" + variables
203234
+ '}';
204235
}
205236
}

driver-core/src/main/com/mongodb/client/model/UpdateOptions.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class UpdateOptions {
3939
private Bson hint;
4040
private String hintString;
4141
private BsonValue comment;
42+
private Bson variables;
4243

4344
/**
4445
* Returns true if a new document should be inserted if there are no matches to the query filter. The default is false.
@@ -225,6 +226,36 @@ public UpdateOptions comment(@Nullable final BsonValue comment) {
225226
return this;
226227
}
227228

229+
/**
230+
* Add top-level variables to the operation
231+
*
232+
* <p>The value of let will be passed to all update and delete, but not insert, commands.
233+
*
234+
* @return the top level variables if set or null.
235+
* @mongodb.server.release 5.0
236+
* @since 4.6
237+
*/
238+
@Nullable
239+
public Bson getLet() {
240+
return variables;
241+
}
242+
243+
/**
244+
* Add top-level variables for the operation
245+
*
246+
* <p>Allows for improved command readability by separating the variables from the query text.
247+
* <p>For bulk operations use: {@link BulkWriteOptions#let(Bson)}
248+
*
249+
* @param variables for the operation or null
250+
* @return this
251+
* @mongodb.server.release 5.0
252+
* @since 4.6
253+
*/
254+
public UpdateOptions let(final Bson variables) {
255+
this.variables = variables;
256+
return this;
257+
}
258+
228259
@Override
229260
public String toString() {
230261
return "UpdateOptions{"
@@ -235,6 +266,7 @@ public String toString() {
235266
+ ", hint=" + hint
236267
+ ", hintString=" + hintString
237268
+ ", comment=" + comment
269+
+ ", let=" + variables
238270
+ '}';
239271
}
240272
}

0 commit comments

Comments
 (0)