Skip to content

Commit 149b2e7

Browse files
CSHARP-3928: Support 'let' option for multiple CRUD commands. (#718)
CSHARP-3928: Support 'let' option for multiple CRUD commands.
1 parent 5c5d17d commit 149b2e7

File tree

62 files changed

+3464
-221
lines changed

Some content is hidden

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

62 files changed

+3464
-221
lines changed

src/MongoDB.Driver.Core/Core/Operations/BulkDeleteOperation.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace MongoDB.Driver.Core.Operations
2121
{
2222
internal class BulkDeleteOperation : BulkUnmixedWriteOperationBase<DeleteRequest>
2323
{
24+
private BsonDocument _let;
25+
2426
// constructors
2527
public BulkDeleteOperation(
2628
CollectionNamespace collectionNamespace,
@@ -30,12 +32,20 @@ public BulkDeleteOperation(
3032
{
3133
}
3234

35+
// public properties
36+
public BsonDocument Let
37+
{
38+
get => _let;
39+
set => _let = value;
40+
}
41+
3342
// methods
3443
protected override IRetryableWriteOperation<BsonDocument> CreateBatchOperation(Batch batch)
3544
{
3645
return new RetryableDeleteCommandOperation(CollectionNamespace, batch.Requests, MessageEncoderSettings)
3746
{
3847
IsOrdered = IsOrdered,
48+
Let = _let,
3949
MaxBatchCount = MaxBatchCount,
4050
RetryRequested = RetryRequested,
4151
WriteConcern = WriteConcern

src/MongoDB.Driver.Core/Core/Operations/BulkMixedWriteOperation.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Linq;
1919
using System.Threading;
2020
using System.Threading.Tasks;
21+
using MongoDB.Bson;
2122
using MongoDB.Driver.Core.Bindings;
2223
using MongoDB.Driver.Core.Connections;
2324
using MongoDB.Driver.Core.Events;
@@ -35,6 +36,7 @@ public class BulkMixedWriteOperation : IWriteOperation<BulkWriteOperationResult>
3536
private bool? _bypassDocumentValidation;
3637
private readonly CollectionNamespace _collectionNamespace;
3738
private bool _isOrdered = true;
39+
private BsonDocument _let;
3840
private int? _maxBatchCount;
3941
private int? _maxBatchLength;
4042
private int? _maxDocumentSize;
@@ -112,6 +114,18 @@ public bool IsOrdered
112114
set { _isOrdered = value; }
113115
}
114116

117+
/// <summary>
118+
/// Gets or sets the let document.
119+
/// </summary>
120+
/// <value>
121+
/// The let document.
122+
/// </value>
123+
public BsonDocument Let
124+
{
125+
get { return _let; }
126+
set { _let = value; }
127+
}
128+
115129
/// <summary>
116130
/// Gets or sets the maximum number of documents in a batch.
117131
/// </summary>
@@ -248,6 +262,7 @@ private IExecutableInRetryableWriteContext<BulkWriteOperationResult> CreateBulkD
248262
return new BulkDeleteOperation(_collectionNamespace, requests, _messageEncoderSettings)
249263
{
250264
IsOrdered = _isOrdered,
265+
Let = _let,
251266
MaxBatchCount = _maxBatchCount,
252267
MaxBatchLength = _maxBatchLength,
253268
WriteConcern = batch.WriteConcern,
@@ -277,6 +292,7 @@ private IExecutableInRetryableWriteContext<BulkWriteOperationResult> CreateBulkU
277292
{
278293
BypassDocumentValidation = _bypassDocumentValidation,
279294
IsOrdered = _isOrdered,
295+
Let = _let,
280296
MaxBatchCount = _maxBatchCount,
281297
MaxBatchLength = _maxBatchLength,
282298
WriteConcern = batch.WriteConcern,

src/MongoDB.Driver.Core/Core/Operations/BulkUpdateOperation.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace MongoDB.Driver.Core.Operations
2121
{
2222
internal class BulkUpdateOperation : BulkUnmixedWriteOperationBase<UpdateRequest>
2323
{
24+
private BsonDocument _let;
25+
2426
// constructors
2527
public BulkUpdateOperation(
2628
CollectionNamespace collectionNamespace,
@@ -30,13 +32,20 @@ public BulkUpdateOperation(
3032
{
3133
}
3234

35+
public BsonDocument Let
36+
{
37+
get => _let;
38+
set => _let = value;
39+
}
40+
3341
// methods
3442
protected override IRetryableWriteOperation<BsonDocument> CreateBatchOperation(Batch batch)
3543
{
3644
return new RetryableUpdateCommandOperation(CollectionNamespace, batch.Requests, MessageEncoderSettings)
3745
{
3846
BypassDocumentValidation = BypassDocumentValidation,
3947
IsOrdered = IsOrdered,
48+
Let = _let,
4049
MaxBatchCount = MaxBatchCount,
4150
RetryRequested = RetryRequested,
4251
WriteConcern = WriteConcern

src/MongoDB.Driver.Core/Core/Operations/FindCommandOperation.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
using MongoDB.Driver.Core.Servers;
2727
using MongoDB.Driver.Core.WireProtocol;
2828
using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
29-
using MongoDB.Shared;
3029

3130
namespace MongoDB.Driver.Core.Operations
3231
{
@@ -54,6 +53,7 @@ public class FindCommandOperation<TDocument> : IReadOperation<IAsyncCursor<TDocu
5453
private BsonDocument _filter;
5554
private int? _firstBatchSize;
5655
private BsonValue _hint;
56+
private BsonDocument _let;
5757
private int? _limit;
5858
private BsonDocument _max;
5959
private TimeSpan? _maxAwaitTime;
@@ -212,6 +212,18 @@ public BsonValue Hint
212212
set { _hint = value; }
213213
}
214214

215+
/// <summary>
216+
/// Gets or sets the let document.
217+
/// </summary>
218+
/// <value>
219+
/// The let document.
220+
/// </value>
221+
public BsonDocument Let
222+
{
223+
get { return _let; }
224+
set { _let = value; }
225+
}
226+
215227
/// <summary>
216228
/// Gets or sets the limit.
217229
/// </summary>
@@ -472,7 +484,8 @@ internal BsonDocument CreateCommand(ConnectionDescription connectionDescription,
472484
{ "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue },
473485
{ "allowPartialResults", () => _allowPartialResults.Value, _allowPartialResults.HasValue && isShardRouter },
474486
{ "collation", () => _collation.ToBsonDocument(), _collation != null },
475-
{ "readConcern", readConcern, readConcern != null }
487+
{ "readConcern", readConcern, readConcern != null },
488+
{ "let", _let, _let != null }
476489
};
477490
}
478491

src/MongoDB.Driver.Core/Core/Operations/FindOneAndDeleteOperation.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using MongoDB.Driver.Core.Connections;
2222
using MongoDB.Driver.Core.Misc;
2323
using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
24-
using MongoDB.Shared;
2524

2625
namespace MongoDB.Driver.Core.Operations
2726
{
@@ -34,6 +33,7 @@ public class FindOneAndDeleteOperation<TResult> : FindAndModifyOperationBase<TRe
3433
// fields
3534
private readonly BsonDocument _filter;
3635
private BsonValue _hint;
36+
private BsonDocument _let;
3737
private TimeSpan? _maxTime;
3838
private BsonDocument _projection;
3939
private BsonDocument _sort;
@@ -76,6 +76,18 @@ public BsonValue Hint
7676
set { _hint = value; }
7777
}
7878

79+
/// <summary>
80+
/// Gets or sets the let document.
81+
/// </summary>
82+
/// <value>
83+
/// The let document.
84+
/// </value>
85+
public BsonDocument Let
86+
{
87+
get { return _let; }
88+
set { _let = value; }
89+
}
90+
7991
/// <summary>
8092
/// Gets or sets the maximum time the server should spend on this operation.
8193
/// </summary>
@@ -136,7 +148,8 @@ internal override BsonDocument CreateCommand(ICoreSessionHandle session, Connect
136148
{ "writeConcern", writeConcern, writeConcern != null },
137149
{ "collation", () => Collation.ToBsonDocument(), Collation != null },
138150
{ "hint", _hint, _hint != null },
139-
{ "txnNumber", () => transactionNumber, transactionNumber.HasValue }
151+
{ "txnNumber", () => transactionNumber, transactionNumber.HasValue },
152+
{ "let", _let, _let != null }
140153
};
141154
}
142155

src/MongoDB.Driver.Core/Core/Operations/FindOneAndReplaceOperation.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
using MongoDB.Driver.Core.Bindings;
2121
using MongoDB.Driver.Core.Connections;
2222
using MongoDB.Driver.Core.Misc;
23-
using MongoDB.Driver.Core.Operations.ElementNameValidators;
2423
using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
25-
using MongoDB.Shared;
2624

2725
namespace MongoDB.Driver.Core.Operations
2826
{
@@ -37,6 +35,7 @@ public class FindOneAndReplaceOperation<TResult> : FindAndModifyOperationBase<TR
3735
private readonly BsonDocument _filter;
3836
private BsonValue _hint;
3937
private bool _isUpsert;
38+
private BsonDocument _let;
4039
private TimeSpan? _maxTime;
4140
private BsonDocument _projection;
4241
private readonly BsonDocument _replacement;
@@ -108,6 +107,18 @@ public bool IsUpsert
108107
set { _isUpsert = value; }
109108
}
110109

110+
/// <summary>
111+
/// Gets or sets the let document.
112+
/// </summary>
113+
/// <value>
114+
/// The let document.
115+
/// </value>
116+
public BsonDocument Let
117+
{
118+
get { return _let; }
119+
set { _let = value; }
120+
}
121+
111122
/// <summary>
112123
/// Gets or sets the maximum time the server should spend on this operation.
113124
/// </summary>
@@ -194,7 +205,8 @@ internal override BsonDocument CreateCommand(ICoreSessionHandle session, Connect
194205
{ "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue },
195206
{ "collation", () => Collation.ToBsonDocument(), Collation != null },
196207
{ "hint", () => _hint, _hint != null },
197-
{ "txnNumber", () => transactionNumber, transactionNumber.HasValue }
208+
{ "txnNumber", () => transactionNumber, transactionNumber.HasValue },
209+
{ "let", _let, _let != null }
198210
};
199211
}
200212

src/MongoDB.Driver.Core/Core/Operations/FindOneAndUpdateOperation.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using MongoDB.Driver.Core.Misc;
2424
using MongoDB.Driver.Core.Operations.ElementNameValidators;
2525
using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
26-
using MongoDB.Shared;
2726

2827
namespace MongoDB.Driver.Core.Operations
2928
{
@@ -39,6 +38,7 @@ public class FindOneAndUpdateOperation<TResult> : FindAndModifyOperationBase<TRe
3938
private readonly BsonDocument _filter;
4039
private BsonValue _hint;
4140
private bool _isUpsert;
41+
private BsonDocument _let;
4242
private TimeSpan? _maxTime;
4343
private BsonDocument _projection;
4444
private ReturnDocument _returnDocument;
@@ -122,6 +122,18 @@ public bool IsUpsert
122122
set { _isUpsert = value; }
123123
}
124124

125+
/// <summary>
126+
/// Gets or sets the let document.
127+
/// </summary>
128+
/// <value>
129+
/// The let document.
130+
/// </value>
131+
public BsonDocument Let
132+
{
133+
get { return _let; }
134+
set { _let = value; }
135+
}
136+
125137
/// <summary>
126138
/// Gets or sets the maximum time the server should spend on this operation.
127139
/// </summary>
@@ -209,7 +221,8 @@ internal override BsonDocument CreateCommand(ICoreSessionHandle session, Connect
209221
{ "collation", () => Collation.ToBsonDocument(), Collation != null },
210222
{ "hint", () => _hint, _hint != null },
211223
{ "arrayFilters", () => new BsonArray(_arrayFilters), _arrayFilters != null },
212-
{ "txnNumber", () => transactionNumber, transactionNumber.HasValue }
224+
{ "txnNumber", () => transactionNumber, transactionNumber.HasValue },
225+
{ "let", _let, _let != null }
213226
};
214227
}
215228

src/MongoDB.Driver.Core/Core/Operations/FindOperation.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class FindOperation<TDocument> : IReadOperation<IAsyncCursor<TDocument>>,
4141
private BsonDocument _filter;
4242
private int? _firstBatchSize;
4343
private BsonValue _hint;
44+
private BsonDocument _let;
4445
private int? _limit;
4546
private BsonDocument _max;
4647
private int? _maxScan;
@@ -200,6 +201,18 @@ public BsonValue Hint
200201
set { _hint = value; }
201202
}
202203

204+
/// <summary>
205+
/// Gets or sets the let document.
206+
/// </summary>
207+
/// <value>
208+
/// The let document.
209+
/// </value>
210+
public BsonDocument Let
211+
{
212+
get { return _let; }
213+
set { _let = value; }
214+
}
215+
203216
/// <summary>
204217
/// Gets or sets the limit.
205218
/// </summary>
@@ -534,6 +547,7 @@ internal FindCommandOperation<TDocument> CreateFindCommandOperation()
534547
Filter = _filter,
535548
Hint = hint,
536549
FirstBatchSize = _firstBatchSize,
550+
Let = _let,
537551
Limit = _limit,
538552
Max = max,
539553
MaxAwaitTime = _maxAwaitTime,

src/MongoDB.Driver.Core/Core/Operations/RetryableDeleteCommandOperation.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class RetryableDeleteCommandOperation : RetryableWriteCommandOperationBas
3636
// private fields
3737
private readonly CollectionNamespace _collectionNamespace;
3838
private readonly BatchableSource<DeleteRequest> _deletes;
39+
private BsonDocument _let;
3940

4041
// constructors
4142
/// <summary>
@@ -55,6 +56,18 @@ public RetryableDeleteCommandOperation(
5556
}
5657

5758
// public properties
59+
/// <summary>
60+
/// Gets or sets the let document.
61+
/// </summary>
62+
/// <value>
63+
/// The let document.
64+
/// </value>
65+
public BsonDocument Let
66+
{
67+
get { return _let; }
68+
set { _let = value; }
69+
}
70+
5871
/// <summary>
5972
/// Gets the collection namespace.
6073
/// </summary>
@@ -95,7 +108,8 @@ protected override BsonDocument CreateCommand(ICoreSessionHandle session, int at
95108
{ "delete", _collectionNamespace.CollectionName },
96109
{ "ordered", IsOrdered },
97110
{ "writeConcern", writeConcern, writeConcern != null },
98-
{ "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue }
111+
{ "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue },
112+
{ "let", _let, _let != null }
99113
};
100114
}
101115

src/MongoDB.Driver.Core/Core/Operations/RetryableUpdateCommandOperation.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class RetryableUpdateCommandOperation : RetryableWriteCommandOperationBas
3737
// private fields
3838
private bool? _bypassDocumentValidation;
3939
private readonly CollectionNamespace _collectionNamespace;
40+
private BsonDocument _let;
4041
private readonly BatchableSource<UpdateRequest> _updates;
4142

4243
// constructors
@@ -78,6 +79,16 @@ public CollectionNamespace CollectionNamespace
7879
get { return _collectionNamespace; }
7980
}
8081

82+
/// <summary>
83+
/// Gets or sets the let document.
84+
/// </summary>
85+
/// <value>The let document.</value>
86+
public BsonDocument Let
87+
{
88+
get { return _let; }
89+
set { _let = value; }
90+
}
91+
8192
/// <summary>
8293
/// Gets the updates.
8394
/// </summary>
@@ -108,7 +119,8 @@ protected override BsonDocument CreateCommand(ICoreSessionHandle session, int at
108119
{ "ordered", IsOrdered },
109120
{ "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue },
110121
{ "writeConcern", writeConcern, writeConcern != null },
111-
{ "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue }
122+
{ "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue },
123+
{ "let", _let, _let != null }
112124
};
113125
}
114126

0 commit comments

Comments
 (0)