@@ -40,6 +40,10 @@ public interface IBulkUpdateOperation<TDocument, TPartialDocument> : IBulkOperat
4040 /// A document to upsert when the specified document to be updated is not found
4141 /// </summary>
4242 TDocument Upsert { get ; set ; }
43+
44+ long ? IfSequenceNumber { get ; set ; }
45+
46+ long ? IfPrimaryTerm { get ; set ; }
4347 }
4448
4549 public class BulkUpdateOperation < TDocument , TPartialDocument > : BulkOperationBase , IBulkUpdateOperation < TDocument , TPartialDocument >
@@ -108,6 +112,10 @@ public BulkUpdateOperation(TDocument idFrom, TPartialDocument update, bool useId
108112 /// </summary>
109113 public TDocument Upsert { get ; set ; }
110114
115+ public long ? IfSequenceNumber { get ; set ; }
116+
117+ public long ? IfPrimaryTerm { get ; set ; }
118+
111119 protected override Type ClrType => typeof ( TDocument ) ;
112120
113121 protected override string Operation => "update" ;
@@ -125,7 +133,9 @@ protected override object GetBody() =>
125133 _Script = Script ,
126134 _Upsert = Upsert ,
127135 _DocAsUpsert = DocAsUpsert ,
128- _ScriptedUpsert = ScriptedUpsert
136+ _ScriptedUpsert = ScriptedUpsert ,
137+ IfPrimaryTerm = IfPrimaryTerm ,
138+ IfSequenceNumber = IfSequenceNumber
129139 } ;
130140 }
131141
@@ -139,11 +149,12 @@ public class BulkUpdateDescriptor<TDocument, TPartialDocument>
139149 protected override string BulkOperationType => "update" ;
140150 TPartialDocument IBulkUpdateOperation < TDocument , TPartialDocument > . Doc { get ; set ; }
141151 bool ? IBulkUpdateOperation < TDocument , TPartialDocument > . DocAsUpsert { get ; set ; }
142-
143152 TDocument IBulkUpdateOperation < TDocument , TPartialDocument > . IdFrom { get ; set ; }
144153 IScript IBulkUpdateOperation < TDocument , TPartialDocument > . Script { get ; set ; }
145154 bool ? IBulkUpdateOperation < TDocument , TPartialDocument > . ScriptedUpsert { get ; set ; }
146155 TDocument IBulkUpdateOperation < TDocument , TPartialDocument > . Upsert { get ; set ; }
156+ long ? IBulkUpdateOperation < TDocument , TPartialDocument > . IfSequenceNumber { get ; set ; }
157+ long ? IBulkUpdateOperation < TDocument , TPartialDocument > . IfPrimaryTerm { get ; set ; }
147158
148159 protected override object GetBulkOperationBody ( ) =>
149160 new BulkUpdateBody < TDocument , TPartialDocument >
@@ -152,7 +163,9 @@ protected override object GetBulkOperationBody() =>
152163 _Script = Self . Script ,
153164 _Upsert = Self . Upsert ,
154165 _DocAsUpsert = Self . DocAsUpsert ,
155- _ScriptedUpsert = Self . ScriptedUpsert
166+ _ScriptedUpsert = Self . ScriptedUpsert ,
167+ IfPrimaryTerm = Self . IfPrimaryTerm ,
168+ IfSequenceNumber = Self . IfSequenceNumber
156169 } ;
157170
158171 protected override Id GetIdForOperation ( Inferrer inferrer ) =>
@@ -209,5 +222,17 @@ public BulkUpdateDescriptor<TDocument, TPartialDocument> Script(Func<ScriptDescr
209222 /// </summary>
210223 public BulkUpdateDescriptor < TDocument , TPartialDocument > RetriesOnConflict ( int ? retriesOnConflict ) =>
211224 Assign ( retriesOnConflict , ( a , v ) => a . RetriesOnConflict = v ) ;
225+
226+ /// <summary>
227+ /// Operations can be made conditional and only be performed if the last modification to the document was assigned the sequence number.
228+ /// </summary>
229+ public BulkUpdateDescriptor < TDocument , TPartialDocument > IfSequenceNumber ( long ? seqNo ) =>
230+ Assign ( seqNo , ( a , v ) => a . IfSequenceNumber = v ) ;
231+
232+ /// <summary>
233+ /// Operations can be made conditional and only be performed if the last modification to the document was assigned the primary term.
234+ /// </summary>
235+ public BulkUpdateDescriptor < TDocument , TPartialDocument > IfPrimaryTerm ( long ? primaryTerm ) =>
236+ Assign ( primaryTerm , ( a , v ) => a . IfSequenceNumber = v ) ;
212237 }
213238}
0 commit comments