Skip to content

Commit 4aeff60

Browse files
GODRIVER-3370 Add bypassEmptyTsReplacement option. (#1927) [release/1.17] (#1954)
Co-authored-by: Qingyang Hu <103950869+qingyang-hu@users.noreply.github.com>
1 parent 566810c commit 4aeff60

11 files changed

+461
-0
lines changed

mongo/bulk_write.go

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type bulkWrite struct {
3939
writeConcern *writeconcern.WriteConcern
4040
result BulkWriteResult
4141
let interface{}
42+
bypassEmptyTsReplacement *bool
4243
}
4344

4445
func (bw *bulkWrite) execute(ctx context.Context) error {
@@ -207,6 +208,10 @@ func (bw *bulkWrite) runInsert(ctx context.Context, batch bulkWriteBatch) (opera
207208
}
208209
op = op.Retry(retry)
209210

211+
if bw.bypassEmptyTsReplacement != nil {
212+
op.BypassEmptyTsReplacement(*bw.bypassEmptyTsReplacement)
213+
}
214+
210215
err := op.Execute(ctx)
211216

212217
return op.Result(), err
@@ -415,6 +420,10 @@ func (bw *bulkWrite) runUpdate(ctx context.Context, batch bulkWriteBatch) (opera
415420
}
416421
op = op.Retry(retry)
417422

423+
if bw.bypassEmptyTsReplacement != nil {
424+
op.BypassEmptyTsReplacement(*bw.bypassEmptyTsReplacement)
425+
}
426+
418427
err := op.Execute(ctx)
419428

420429
return op.Result(), err

mongo/collection.go

+17
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func (coll *Collection) BulkWrite(ctx context.Context, models []WriteModel,
234234
selector: selector,
235235
writeConcern: wc,
236236
let: bwo.Let,
237+
bypassEmptyTsReplacement: bwo.BypassEmptyTsReplacement,
237238
}
238239

239240
err = op.execute(ctx)
@@ -307,6 +308,9 @@ func (coll *Collection) insert(ctx context.Context, documents []interface{},
307308
if imo.Ordered != nil {
308309
op = op.Ordered(*imo.Ordered)
309310
}
311+
if imo.BypassEmptyTsReplacement != nil {
312+
op = op.BypassEmptyTsReplacement(*imo.BypassEmptyTsReplacement)
313+
}
310314
retry := driver.RetryNone
311315
if coll.client.retryWrites {
312316
retry = driver.RetryOncePerCommand
@@ -355,6 +359,9 @@ func (coll *Collection) InsertOne(ctx context.Context, document interface{},
355359
if ioOpts.Comment != nil {
356360
imOpts.SetComment(ioOpts.Comment)
357361
}
362+
if ioOpts.BypassEmptyTsReplacement != nil {
363+
imOpts.BypassEmptyTsReplacement = ioOpts.BypassEmptyTsReplacement
364+
}
358365
res, err := coll.insert(ctx, []interface{}{document}, imOpts)
359366

360367
rr, err := processWriteError(err)
@@ -609,6 +616,9 @@ func (coll *Collection) updateOrReplace(ctx context.Context, filter bsoncore.Doc
609616
}
610617
op = op.Comment(comment)
611618
}
619+
if uo.BypassEmptyTsReplacement != nil {
620+
op.BypassEmptyTsReplacement(*uo.BypassEmptyTsReplacement)
621+
}
612622
retry := driver.RetryNone
613623
// retryable writes are only enabled updateOne/replaceOne operations
614624
if !multi && coll.client.retryWrites {
@@ -760,6 +770,7 @@ func (coll *Collection) ReplaceOne(ctx context.Context, filter interface{},
760770
uOpts.Hint = opt.Hint
761771
uOpts.Let = opt.Let
762772
uOpts.Comment = opt.Comment
773+
uOpts.BypassEmptyTsReplacement = opt.BypassEmptyTsReplacement
763774
updateOptions = append(updateOptions, uOpts)
764775
}
765776

@@ -1659,6 +1670,9 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{
16591670
}
16601671
op = op.Let(let)
16611672
}
1673+
if fo.BypassEmptyTsReplacement != nil {
1674+
op = op.BypassEmptyTsReplacement(*fo.BypassEmptyTsReplacement)
1675+
}
16621676

16631677
return coll.findAndModify(ctx, op)
16641678
}
@@ -1765,6 +1779,9 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}
17651779
}
17661780
op = op.Let(let)
17671781
}
1782+
if fo.BypassEmptyTsReplacement != nil {
1783+
op = op.BypassEmptyTsReplacement(*fo.BypassEmptyTsReplacement)
1784+
}
17681785

17691786
return coll.findAndModify(ctx, op)
17701787
}

0 commit comments

Comments
 (0)