Skip to content

Commit aedf097

Browse files
authored
CSHARP-5405: Remove the BSON document size validation requirement for the client bulk write operation (#1561)
1 parent fc052f4 commit aedf097

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

src/MongoDB.Driver/Core/WireProtocol/Messages/Encoders/BinaryEncoders/ClientBulkWriteOpsSectionFormatter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void FormatSection(ClientBulkWriteOpsCommandMessageSection section, IBson
7474

7575
var batch = section.Documents;
7676
var maxDocumentSize = section.MaxDocumentSize ?? binaryWriter.Settings.MaxDocumentSize;
77-
binaryWriter.PushSettings(s => ((BsonBinaryWriterSettings)s).MaxDocumentSize = maxDocumentSize);
77+
binaryWriter.PushSettings(s => ((BsonBinaryWriterSettings)s).MaxDocumentSize = int.MaxValue);
7878
binaryWriter.PushElementNameValidator(NoOpElementNameValidator.Instance);
7979
_nsInfoWriter.PushSettings(s => ((BsonBinaryWriterSettings)s).MaxDocumentSize = maxDocumentSize);
8080
try
@@ -98,6 +98,12 @@ public void FormatSection(ClientBulkWriteOpsCommandMessageSection section, IBson
9898
break;
9999
}
100100
}
101+
102+
if (processedCount == 0)
103+
{
104+
throw new FormatException("Cannot send empty batch.");
105+
}
106+
101107
batch.SetProcessedCount(processedCount);
102108
stream.BackpatchSize(startPosition);
103109

tests/MongoDB.Driver.Tests/Specifications/crud/prose-tests/CrudProseTests.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
using MongoDB.Driver.Core.TestHelpers;
2828
using MongoDB.Driver.Core.TestHelpers.Logging;
2929
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
30-
using MongoDB.Driver.Encryption;
31-
using MongoDB.Driver.TestHelpers;
3230
using MongoDB.TestHelpers.XunitExtensions;
3331
using Xunit;
3432
using Xunit.Abstractions;
@@ -410,36 +408,6 @@ public async Task MongoClient_bulkWrite_handles_getMore_error([Values(true, fals
410408
eventCapturer.Events.Should().Contain(e => ((CommandStartedEvent)e).CommandName == "killCursors");
411409
}
412410

413-
// https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L371
414-
[Theory]
415-
[ParameterAttributeData]
416-
internal async Task MongoClient_bulkWrite_returns_error_for_unacknowledged_too_large_insert(
417-
[Values(true, false)] bool async,
418-
[Values(true, false)] bool isReplace)
419-
{
420-
RequireServer.Check().Supports(Feature.ClientBulkWrite).Serverless(false);
421-
var maxDocumentSize = DriverTestConfiguration.GetConnectionDescription().MaxDocumentSize;
422-
423-
var document = new BsonDocument() { { "a", new string('b', maxDocumentSize) } };
424-
BulkWriteModel[] models = isReplace
425-
? new[] { new BulkWriteReplaceOneModel<BsonDocument>("db.coll", Builders<BsonDocument>.Filter.Empty, document) }
426-
: new[] { new BulkWriteInsertOneModel<BsonDocument>("db.coll", document) };
427-
428-
using var client = CreateMongoClient(null);
429-
var bulkWriteOptions = new ClientBulkWriteOptions
430-
{
431-
WriteConcern = WriteConcern.Unacknowledged,
432-
IsOrdered = false
433-
};
434-
435-
var exception = async
436-
? await Record.ExceptionAsync(() => client.BulkWriteAsync(models, bulkWriteOptions))
437-
: Record.Exception(() => client.BulkWrite(models, bulkWriteOptions));
438-
439-
var bulkWriteException = exception.Should().BeOfType<ClientBulkWriteException>().Subject;
440-
bulkWriteException.InnerException.Should().BeOfType<FormatException>();
441-
}
442-
443411
// https://github.com/mongodb/specifications/blob/7517681e6a3186cb7f3114314a9fe1bc3a747b9f/source/crud/tests/README.md?plain=1#L422
444412
//
445413
// This test is commented out because calculations in spec does not include "$db" and "lsid" fields of bulkWrite command.

0 commit comments

Comments
 (0)