From fc91428893d9021d90c8ea9f1128a60f9f5c976a Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Wed, 4 Dec 2024 17:41:14 -0500 Subject: [PATCH] GODRIVER-3421 Remove the BSON document size validation. --- internal/integration/collection_test.go | 2 +- internal/integration/crud_prose_test.go | 26 -------- mongo/client_bulk_write.go | 34 ++-------- mongo/client_bulk_write_test.go | 80 +++++++++++++++++----- mongo/client_test.go | 27 ++++++++ x/mongo/driver/batches.go | 16 ++--- x/mongo/driver/batches_test.go | 88 +++++++++---------------- x/mongo/driver/operation.go | 37 +++++------ 8 files changed, 152 insertions(+), 158 deletions(-) diff --git a/internal/integration/collection_test.go b/internal/integration/collection_test.go index e5b4b6e4c4..056a527768 100644 --- a/internal/integration/collection_test.go +++ b/internal/integration/collection_test.go @@ -167,7 +167,7 @@ func TestCollection(t *testing.T) { mt.Run("large document batches", func(mt *mtest.T) { mt.Parallel() - docs := []interface{}{create16MBDocument(mt), create16MBDocument(mt)} + docs := []interface{}{create16MBDocument(mt), create16MBDocument(mt), create16MBDocument(mt)} _, err := mt.Coll.InsertMany(context.Background(), docs) assert.Nil(mt, err, "InsertMany error: %v", err) evt := mt.GetStartedEvent() diff --git a/internal/integration/crud_prose_test.go b/internal/integration/crud_prose_test.go index fc4a43a4f7..3b5a069535 100644 --- a/internal/integration/crud_prose_test.go +++ b/internal/integration/crud_prose_test.go @@ -745,32 +745,6 @@ func TestClientBulkWrite(t *testing.T) { assert.Equal(mt, 1, killCursorsCalled, "expected %d killCursors call, got: %d", 1, killCursorsCalled) }) - mt.Run("bulkWrite returns error for unacknowledged too-large insert", func(mt *mtest.T) { - mt.ResetClient(options.Client()) - var hello struct { - MaxBsonObjectSize int - } - err := mt.DB.RunCommand(context.Background(), bson.D{{"hello", 1}}).Decode(&hello) - require.NoError(mt, err, "Hello error: %v", err) - mt.Run("insert", func(mt *mtest.T) { - models := (&mongo.ClientWriteModels{}). - AppendInsertOne("db", "coll", &mongo.ClientInsertOneModel{ - Document: bson.D{{"a", strings.Repeat("b", hello.MaxBsonObjectSize)}}, - }) - _, err := mt.Client.BulkWrite(context.Background(), models, options.ClientBulkWrite().SetOrdered(false).SetWriteConcern(writeconcern.Unacknowledged())) - require.EqualError(mt, err, driver.ErrDocumentTooLarge.Error()) - }) - mt.Run("replace", func(mt *mtest.T) { - models := (&mongo.ClientWriteModels{}). - AppendReplaceOne("db", "coll", &mongo.ClientReplaceOneModel{ - Filter: bson.D{}, - Replacement: bson.D{{"a", strings.Repeat("b", hello.MaxBsonObjectSize)}}, - }) - _, err := mt.Client.BulkWrite(context.Background(), models, options.ClientBulkWrite().SetOrdered(false).SetWriteConcern(writeconcern.Unacknowledged())) - require.EqualError(mt, err, driver.ErrDocumentTooLarge.Error()) - }) - }) - mt.Run("bulkWrite batch splits when the addition of a new namespace exceeds the maximum message size", func(mt *mtest.T) { type cmd struct { Ops []bson.D diff --git a/mongo/client_bulk_write.go b/mongo/client_bulk_write.go index ed29a74289..4560654cd5 100644 --- a/mongo/client_bulk_write.go +++ b/mongo/client_bulk_write.go @@ -191,6 +191,8 @@ type modelBatches struct { writeErrors map[int]WriteError } +var _ driver.OperationBatches = &modelBatches{} + func (mb *modelBatches) IsOrdered() *bool { return &mb.ordered } @@ -209,7 +211,7 @@ func (mb *modelBatches) Size() int { return len(mb.models) - mb.offset } -func (mb *modelBatches) AppendBatchSequence(dst []byte, maxCount, maxDocSize, totalSize int) (int, []byte, error) { +func (mb *modelBatches) AppendBatchSequence(dst []byte, maxCount, totalSize int) (int, []byte, error) { fn := functionSet{ appendStart: func(dst []byte, identifier string) (int32, []byte) { var idx int32 @@ -228,10 +230,10 @@ func (mb *modelBatches) AppendBatchSequence(dst []byte, maxCount, maxDocSize, to return dst }, } - return mb.appendBatches(fn, dst, maxCount, maxDocSize, totalSize) + return mb.appendBatches(fn, dst, maxCount, totalSize) } -func (mb *modelBatches) AppendBatchArray(dst []byte, maxCount, maxDocSize, totalSize int) (int, []byte, error) { +func (mb *modelBatches) AppendBatchArray(dst []byte, maxCount, totalSize int) (int, []byte, error) { fn := functionSet{ appendStart: bsoncore.AppendArrayElementStart, appendDocument: bsoncore.AppendDocumentElement, @@ -240,7 +242,7 @@ func (mb *modelBatches) AppendBatchArray(dst []byte, maxCount, maxDocSize, total return dst }, } - return mb.appendBatches(fn, dst, maxCount, maxDocSize, totalSize) + return mb.appendBatches(fn, dst, maxCount, totalSize) } type functionSet struct { @@ -249,7 +251,7 @@ type functionSet struct { updateLength func([]byte, int32, int32) []byte } -func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, maxDocSize, totalSize int) (int, []byte, error) { +func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, totalSize int) (int, []byte, error) { if mb.Size() == 0 { return 0, dst, io.EOF } @@ -269,8 +271,6 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, maxD } canRetry := true - checkSize := true - l := len(dst) opsIdx, dst := fn.appendStart(dst, "ops") @@ -291,13 +291,11 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, maxD var err error switch model := mb.models[i].model.(type) { case *ClientInsertOneModel: - checkSize = false mb.cursorHandlers = append(mb.cursorHandlers, mb.appendInsertResult) var id interface{} id, doc, err = (&clientInsertDoc{ namespace: nsIdx, document: model.Document, - sizeLimit: maxDocSize, }).marshal(mb.client.bsonOpts, mb.client.registry) if err != nil { break @@ -331,7 +329,6 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, maxD checkDollarKey: true, }).marshal(mb.client.bsonOpts, mb.client.registry) case *ClientReplaceOneModel: - checkSize = false mb.cursorHandlers = append(mb.cursorHandlers, mb.appendUpdateResult) doc, err = (&clientUpdateDoc{ namespace: nsIdx, @@ -343,7 +340,6 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, maxD upsert: model.Upsert, multi: false, checkDollarKey: false, - sizeLimit: maxDocSize, }).marshal(mb.client.bsonOpts, mb.client.registry) case *ClientDeleteOneModel: mb.cursorHandlers = append(mb.cursorHandlers, mb.appendDeleteResult) @@ -371,9 +367,6 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, maxD return 0, nil, err } length := len(doc) - if maxDocSize > 0 && length > maxDocSize+16*1024 { - return 0, nil, driver.ErrDocumentTooLarge - } if !exists { length += len(ns) } @@ -398,9 +391,6 @@ func (mb *modelBatches) appendBatches(fn functionSet, dst []byte, maxCount, maxD dst = fn.updateLength(dst, opsIdx, int32(len(dst[opsIdx:]))) nsDst = fn.updateLength(nsDst, nsIdx, int32(len(nsDst[nsIdx:]))) dst = append(dst, nsDst...) - if checkSize && maxDocSize > 0 && len(dst)-l > maxDocSize+16*1024 { - return 0, nil, driver.ErrDocumentTooLarge - } mb.retryMode = driver.RetryNone if mb.client.retryWrites && canRetry { @@ -584,8 +574,6 @@ func (mb *modelBatches) appendUpdateResult(cur *cursorInfo, raw bson.Raw) bool { type clientInsertDoc struct { namespace int document interface{} - - sizeLimit int } func (d *clientInsertDoc) marshal(bsonOpts *options.BSONOptions, registry *bson.Registry) (interface{}, bsoncore.Document, error) { @@ -596,9 +584,6 @@ func (d *clientInsertDoc) marshal(bsonOpts *options.BSONOptions, registry *bson. if err != nil { return nil, nil, err } - if d.sizeLimit > 0 && len(f) > d.sizeLimit { - return nil, nil, driver.ErrDocumentTooLarge - } var id interface{} f, id, err = ensureID(f, bson.NilObjectID, bsonOpts, registry) if err != nil { @@ -619,8 +604,6 @@ type clientUpdateDoc struct { upsert *bool multi bool checkDollarKey bool - - sizeLimit int } func (d *clientUpdateDoc) marshal(bsonOpts *options.BSONOptions, registry *bson.Registry) (bsoncore.Document, error) { @@ -641,9 +624,6 @@ func (d *clientUpdateDoc) marshal(bsonOpts *options.BSONOptions, registry *bson. if err != nil { return nil, err } - if d.sizeLimit > 0 && len(u.Data) > d.sizeLimit { - return nil, driver.ErrDocumentTooLarge - } doc = bsoncore.AppendValueElement(doc, "updateMods", u) doc = bsoncore.AppendBooleanElement(doc, "multi", d.multi) diff --git a/mongo/client_bulk_write_test.go b/mongo/client_bulk_write_test.go index b5191a2861..eec43f5dae 100644 --- a/mongo/client_bulk_write_test.go +++ b/mongo/client_bulk_write_test.go @@ -17,22 +17,23 @@ import ( func TestBatches(t *testing.T) { t.Parallel() - t.Run("test Addvancing", func(t *testing.T) { - t.Parallel() + t.Parallel() - batches := &modelBatches{ - models: make([]clientWriteModel, 2), - } - batches.AdvanceBatches(3) - size := batches.Size() - assert.Equal(t, 0, size, "expected: %d, got: %d", 1, size) - }) - t.Run("test appendBatches", func(t *testing.T) { - t.Parallel() + batches := &modelBatches{ + models: make([]clientWriteModel, 2), + } + batches.AdvanceBatches(3) + size := batches.Size() + assert.Equal(t, 0, size, "expected: %d, got: %d", 1, size) +} + +func TestAppendBatchSequence(t *testing.T) { + t.Parallel() + newBatches := func(t *testing.T) *modelBatches { client, err := newClient() require.NoError(t, err, "NewClient error: %v", err) - batches := &modelBatches{ + return &modelBatches{ client: client, models: []clientWriteModel{ {"ns0", nil}, @@ -52,12 +53,15 @@ func TestBatches(t *testing.T) { Acknowledged: true, }, } - var n int + } + t.Run("test appendBatches", func(t *testing.T) { + t.Parallel() + + batches := newBatches(t) const limitBigEnough = 16_000 - // test the "maxCount" that truncates the output - n, _, err = batches.AppendBatchSequence(nil, 4, limitBigEnough, limitBigEnough) + n, _, err := batches.AppendBatchSequence(nil, 4, limitBigEnough) require.NoError(t, err, "AppendBatchSequence error: %v", err) - assert.Equal(t, 3, n, "expected %d appendings, got: %d", 3, n) + require.Equal(t, 3, n, "expected %d appendings, got: %d", 3, n) _ = batches.cursorHandlers[0](&cursorInfo{Ok: true, Idx: 0}, nil) _ = batches.cursorHandlers[1](&cursorInfo{Ok: true, Idx: 1}, nil) @@ -71,6 +75,50 @@ func TestBatches(t *testing.T) { assert.True(t, ok, "expected an insert results") _, ok = batches.result.DeleteResults[3] + assert.True(t, ok, "expected an delete results") + }) + t.Run("test appendBatches with maxCount", func(t *testing.T) { + t.Parallel() + + batches := newBatches(t) + const limitBigEnough = 16_000 + n, _, err := batches.AppendBatchSequence(nil, 2, limitBigEnough) + require.NoError(t, err, "AppendBatchSequence error: %v", err) + require.Equal(t, 2, n, "expected %d appendings, got: %d", 2, n) + + _ = batches.cursorHandlers[0](&cursorInfo{Ok: true, Idx: 0}, nil) + _ = batches.cursorHandlers[1](&cursorInfo{Ok: true, Idx: 1}, nil) + + ins, ok := batches.result.InsertResults[1] + assert.True(t, ok, "expected an insert results") + assert.NotNil(t, ins.InsertedID, "expected an ID") + + _, ok = batches.result.UpdateResults[2] + assert.True(t, ok, "expected an insert results") + + _, ok = batches.result.DeleteResults[3] + assert.False(t, ok, "expected an delete results") + }) + t.Run("test appendBatches with totalSize", func(t *testing.T) { + t.Parallel() + + batches := newBatches(t) + const limit = 1200 // > ( 166 first two batches + 1000 overhead ) + n, _, err := batches.AppendBatchSequence(nil, 4, limit) + require.NoError(t, err, "AppendBatchSequence error: %v", err) + require.Equal(t, 2, n, "expected %d appendings, got: %d", 2, n) + + _ = batches.cursorHandlers[0](&cursorInfo{Ok: true, Idx: 0}, nil) + _ = batches.cursorHandlers[1](&cursorInfo{Ok: true, Idx: 1}, nil) + + ins, ok := batches.result.InsertResults[1] assert.True(t, ok, "expected an insert results") + assert.NotNil(t, ins.InsertedID, "expected an ID") + + _, ok = batches.result.UpdateResults[2] + assert.True(t, ok, "expected an insert results") + + _, ok = batches.result.DeleteResults[3] + assert.False(t, ok, "expected an delete results") }) } diff --git a/mongo/client_test.go b/mongo/client_test.go index 70e2075124..8465045d47 100644 --- a/mongo/client_test.go +++ b/mongo/client_test.go @@ -11,6 +11,7 @@ import ( "errors" "math" "os" + "strings" "testing" "time" @@ -516,4 +517,30 @@ func TestClient(t *testing.T) { errmsg := `invalid value "-1s" for "Timeout": value must be positive` assert.Equal(t, errmsg, err.Error(), "expected error %v, got %v", errmsg, err.Error()) }) + t.Run("bulkWrite with large messages", func(t *testing.T) { + var bulkWrites int + cmdMonitor := &event.CommandMonitor{ + Started: func(_ context.Context, evt *event.CommandStartedEvent) { + if evt.CommandName == "bulkWrite" { + bulkWrites++ + } + }, + } + cs := integtest.ConnString(t) + clientOpts := options.Client().ApplyURI(cs.Original).SetMonitor(cmdMonitor) + client, err := Connect(clientOpts) + assert.Nil(t, err, "Connect error: %v", err) + defer func() { + _ = client.Disconnect(bgCtx) + }() + document := bson.D{{"largeField", strings.Repeat("a", 16777216-100)}} // Adjust size to account for BSON overhead + models := &ClientWriteModels{} + models = models.AppendInsertOne("db", "x", NewClientInsertOneModel().SetDocument(document)) + models = models.AppendInsertOne("db", "x", NewClientInsertOneModel().SetDocument(document)) + models = models.AppendInsertOne("db", "x", NewClientInsertOneModel().SetDocument(document)) + + _, err = client.BulkWrite(context.Background(), models) + require.NoError(t, err) + assert.Equal(t, 2, bulkWrites, "expected %d bulkWrites, got %d", 2, bulkWrites) + }) } diff --git a/x/mongo/driver/batches.go b/x/mongo/driver/batches.go index 4f096616a7..51a32bc962 100644 --- a/x/mongo/driver/batches.go +++ b/x/mongo/driver/batches.go @@ -24,10 +24,12 @@ type Batches struct { offset int } +var _ OperationBatches = &Batches{} + // AppendBatchSequence appends dst with document sequence of batches as long as the limits of max count, max // document size, or total size allows. It returns the number of batches appended, the new appended slice, and // any error raised. It returns the origenal input slice if nothing can be appends within the limits. -func (b *Batches) AppendBatchSequence(dst []byte, maxCount, maxDocSize, _ int) (int, []byte, error) { +func (b *Batches) AppendBatchSequence(dst []byte, maxCount, totalSize int) (int, []byte, error) { if b.Size() == 0 { return 0, dst, io.EOF } @@ -44,11 +46,8 @@ func (b *Batches) AppendBatchSequence(dst []byte, maxCount, maxDocSize, _ int) ( break } doc := b.Documents[i] - if len(doc) > maxDocSize { - break - } size += len(doc) - if size > maxDocSize { + if size > totalSize { break } dst = append(dst, doc...) @@ -64,7 +63,7 @@ func (b *Batches) AppendBatchSequence(dst []byte, maxCount, maxDocSize, _ int) ( // AppendBatchArray appends dst with array of batches as long as the limits of max count, max document size, or // total size allows. It returns the number of batches appended, the new appended slice, and any error raised. It // returns the origenal input slice if nothing can be appends within the limits. -func (b *Batches) AppendBatchArray(dst []byte, maxCount, maxDocSize, _ int) (int, []byte, error) { +func (b *Batches) AppendBatchArray(dst []byte, maxCount, totalSize int) (int, []byte, error) { if b.Size() == 0 { return 0, dst, io.EOF } @@ -77,11 +76,8 @@ func (b *Batches) AppendBatchArray(dst []byte, maxCount, maxDocSize, _ int) (int break } doc := b.Documents[i] - if len(doc) > maxDocSize { - break - } size += len(doc) - if size > maxDocSize { + if size > totalSize { break } dst = bsoncore.AppendDocumentElement(dst, strconv.Itoa(n), doc) diff --git a/x/mongo/driver/batches_test.go b/x/mongo/driver/batches_test.go index 95cdb674de..5a028c96dd 100644 --- a/x/mongo/driver/batches_test.go +++ b/x/mongo/driver/batches_test.go @@ -33,69 +33,41 @@ func TestAdvancing(t *testing.T) { } func TestAppendBatchSequence(t *testing.T) { - t.Run("Append 0", func(t *testing.T) { - batches := newTestBatches(t) - - got := []byte{42} - var n int - var err error - n, got, err = batches.AppendBatchSequence(got, 2, len(batches.Documents[0])-1, 0) - assert.NoError(t, err) - assert.Equal(t, 0, n) - - assert.Equal(t, []byte{42}, got) - }) - t.Run("Append 1", func(t *testing.T) { - batches := newTestBatches(t) + batches := newTestBatches(t) - got := []byte{42} - var n int - var err error - n, got, err = batches.AppendBatchSequence(got, 2, len(batches.Documents[0]), 0) - assert.NoError(t, err) - assert.Equal(t, 1, n) + got := []byte{42} + var n int + var err error + n, got, err = batches.AppendBatchSequence(got, 2, len(batches.Documents[0])) + assert.NoError(t, err) + assert.Equal(t, 1, n) - var idx int32 - dst := []byte{42} - dst = wiremessage.AppendMsgSectionType(dst, wiremessage.DocumentSequence) - idx, dst = bsoncore.ReserveLength(dst) - dst = append(dst, "foobar"...) - dst = append(dst, 0x00) - dst = append(dst, "Lorem ipsum dolor sit amet"...) - dst = bsoncore.UpdateLength(dst, idx, int32(len(dst[idx:]))) - assert.Equal(t, dst, got) - }) + var idx int32 + dst := []byte{42} + dst = wiremessage.AppendMsgSectionType(dst, wiremessage.DocumentSequence) + idx, dst = bsoncore.ReserveLength(dst) + dst = append(dst, "foobar"...) + dst = append(dst, 0x00) + dst = append(dst, "Lorem ipsum dolor sit amet"...) + dst = bsoncore.UpdateLength(dst, idx, int32(len(dst[idx:]))) + assert.Equal(t, dst, got) } func TestAppendBatchArray(t *testing.T) { - t.Run("Append 0", func(t *testing.T) { - batches := newTestBatches(t) - - got := []byte{42} - var n int - var err error - n, got, err = batches.AppendBatchArray(got, 2, len(batches.Documents[0])-1, 0) - assert.NoError(t, err) - assert.Equal(t, 0, n) - - assert.Equal(t, []byte{42}, got) - }) - t.Run("Append 1", func(t *testing.T) { - batches := newTestBatches(t) + batches := newTestBatches(t) - got := []byte{42} - var n int - var err error - n, got, err = batches.AppendBatchArray(got, 2, len(batches.Documents[0]), 0) - assert.NoError(t, err) - assert.Equal(t, 1, n) + got := []byte{42} + var n int + var err error + n, got, err = batches.AppendBatchArray(got, 2, len(batches.Documents[0])) + assert.NoError(t, err) + assert.Equal(t, 1, n) - var idx int32 - dst := []byte{42} - idx, dst = bsoncore.AppendArrayElementStart(dst, "foobar") - dst = bsoncore.AppendDocumentElement(dst, "0", []byte("Lorem ipsum dolor sit amet")) - dst, err = bsoncore.AppendArrayEnd(dst, idx) - assert.NoError(t, err) - assert.Equal(t, dst, got) - }) + var idx int32 + dst := []byte{42} + idx, dst = bsoncore.AppendArrayElementStart(dst, "foobar") + dst = bsoncore.AppendDocumentElement(dst, "0", []byte("Lorem ipsum dolor sit amet")) + dst, err = bsoncore.AppendArrayEnd(dst, idx) + assert.NoError(t, err) + assert.Equal(t, dst, got) } diff --git a/x/mongo/driver/operation.go b/x/mongo/driver/operation.go index fdf8732f21..8659c92e90 100644 --- a/x/mongo/driver/operation.go +++ b/x/mongo/driver/operation.go @@ -184,6 +184,16 @@ func redactFinishedInformationResponse(info finishedInformation) bson.Raw { return bson.Raw{} } +// OperationBatches contains the documents that are split when executing a write command that potentially +// has more documents than can fit in a single command. +type OperationBatches interface { + AppendBatchSequence(dst []byte, maxCount int, totalSize int) (int, []byte, error) + AppendBatchArray(dst []byte, maxCount int, totalSize int) (int, []byte, error) + IsOrdered() *bool + AdvanceBatches(n int) + Size() int +} + // Operation is used to execute an operation. It contains all of the common code required to // select a server, transform an operation into a command, write the command to a connection from // the selected server, read a response from that connection, process the response, and potentially @@ -269,15 +279,8 @@ type Operation struct { // Batches contains the documents that are split when executing a write command that potentially // has more documents than can fit in a single command. This should only be specified for - // commands that are batch compatible. For more information, please refer to the definition of - // Batches. - Batches interface { - AppendBatchSequence(dst []byte, maxCount int, maxDocSize int, totalSize int) (int, []byte, error) - AppendBatchArray(dst []byte, maxCount int, maxDocSize int, totalSize int) (int, []byte, error) - IsOrdered() *bool - AdvanceBatches(n int) - Size() int - } + // commands that are batch compatible. + Batches OperationBatches // Legacy sets the legacy type for this operation. There are only 3 types that require legacy // support: find, getMore, and killCursors. For more information about LegacyOperationKind, @@ -1371,7 +1374,7 @@ func (op Operation) createWireMessage( if err == nil && op.Batches != nil { batchOffset = len(dst) info.processedBatches, dst, err = op.Batches.AppendBatchSequence(dst, - int(desc.MaxBatchCount), int(desc.MaxDocumentSize), int(desc.MaxDocumentSize), + int(desc.MaxBatchCount), int(desc.MaxMessageSize), ) if err != nil { break @@ -1383,12 +1386,8 @@ func (op Operation) createWireMessage( default: var batches []byte if op.Batches != nil { - maxDocSize := -1 - if unacknowledged { - maxDocSize = int(desc.MaxDocumentSize) - } info.processedBatches, batches, err = op.Batches.AppendBatchSequence(batches, - int(desc.MaxBatchCount), maxDocSize, int(desc.MaxMessageSize), + int(desc.MaxBatchCount), int(desc.MaxMessageSize), ) if err != nil { break @@ -1443,14 +1442,13 @@ func (op Operation) addEncryptCommandFields(ctx context.Context, dst []byte, des var n int if op.Batches != nil { if maxBatchCount := int(desc.MaxBatchCount); maxBatchCount > 1 { - n, cmdDst, err = op.Batches.AppendBatchArray(cmdDst, maxBatchCount, cryptMaxBsonObjectSize, cryptMaxBsonObjectSize) + n, cmdDst, err = op.Batches.AppendBatchArray(cmdDst, maxBatchCount, cryptMaxBsonObjectSize) if err != nil { return 0, nil, err } } if n == 0 { - maxDocumentSize := int(desc.MaxDocumentSize) - n, cmdDst, err = op.Batches.AppendBatchArray(cmdDst, 1, maxDocumentSize, maxDocumentSize) + n, cmdDst, err = op.Batches.AppendBatchArray(cmdDst, 1, int(desc.MaxMessageSize)) if err != nil { return 0, nil, err } @@ -1483,8 +1481,7 @@ func (op Operation) addLegacyCommandFields(dst []byte, desc description.Selected return 0, dst, nil } var n int - maxDocumentSize := int(desc.MaxDocumentSize) - n, dst, err = op.Batches.AppendBatchArray(dst, int(desc.MaxBatchCount), maxDocumentSize, maxDocumentSize) + n, dst, err = op.Batches.AppendBatchArray(dst, int(desc.MaxBatchCount), int(desc.MaxMessageSize)) if err != nil { return 0, nil, err }