File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 22
22
ErrMultiDocCommandResponse = errors .New ("command returned multiple documents" )
23
23
// ErrNoDocCommandResponse occurs when the server indicated a response existed, but none was found.
24
24
ErrNoDocCommandResponse = errors .New ("command returned no documents" )
25
+ // ErrDocumentTooLarge occurs when a document that is larger than the maximum size accepted by a
26
+ // server is passed to an insert command.
27
+ ErrDocumentTooLarge = errors .New ("an inserted document is too large" )
25
28
)
26
29
27
30
// QueryFailureError is an error representing a command failure as a document.
Original file line number Diff line number Diff line change @@ -64,6 +64,9 @@ splitInserts:
64
64
return nil , err
65
65
}
66
66
67
+ if int (itsize ) > targetBatchSize {
68
+ return nil , ErrDocumentTooLarge
69
+ }
67
70
if size + int (itsize ) > targetBatchSize {
68
71
break assembleBatch
69
72
}
Original file line number Diff line number Diff line change @@ -78,4 +78,12 @@ func TestInsertCommandSplitting(t *testing.T) {
78
78
}
79
79
80
80
})
81
+ t .Run ("document_larger_than_max_size" , func (t * testing.T ) {
82
+ i := & Insert {}
83
+ i .Docs = append (i .Docs , bson .NewDocument (bson .EC .String ("a" , "bcdefghijklmnopqrstuvwxyz" )))
84
+ _ , err := i .split (100 , 5 )
85
+ if err != ErrDocumentTooLarge {
86
+ t .Errorf ("Expected a too large error. got %v; want %v" , err , ErrDocumentTooLarge )
87
+ }
88
+ })
81
89
}
You can’t perform that action at this time.
0 commit comments