Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-5511

New Bulk API MongoClient.BulkWriteAsync() doesn't actually work for mongodb version 7.0

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 3.0.0, 3.1.0, 3.2.0
    • Component/s: Bulk API
    • None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      The new Bulk API method that is called directly on MongoClient, the MongoClient.BulkWriteAsync() doesn't seem to be compatible with mongodb version 7, though the C# driver v3.0+ is claimed to be fully compatible with the database version 7.0. Compatibility - C#/.NET v3.2

      The Bulk API was compatible with mongodb version 8.0,

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      It seems to be the case for all C# driver versions 3.0+. I tested against 3-node replica set in docker-compose. Tested against both mongodb v7 and v8

      How to Reproduce

      Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

      C# driver v3.0+

      3-node replica set of Mongodb version 7.0 (in my case was 7.0.16) 

      code to reproduce the simplest scenario:

      using var client = new MongoClient("conn_str");
        
        var upd1Doc = new BulkWriteUpdateOneModel<BsonDocument>("test_db.test_coll",
            Builders<BsonDocument>.Filter.Eq("_id", 1),
            Builders<BsonDocument>.Update.Set("new_field", "val4"), isUpsert: true);  var res = await client.BulkWriteAsync(new List<BulkWriteModel>() { upd1Doc }); 

      To partially fix the problem it helper to change ClientBulkWriteOperation.CreateCommand() method to exclude "errorsOnly" command parameter, as it seems that it is not valid for mongodb v7.0 bulk write command.

      __

      protected override BsonDocument CreateCommand(ICoreSessionHandle session, int attempt, long? transactionNumber)
      {
          var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern);
          return new BsonDocument
          {
              { "bulkWrite", 1 },
              //{ "errorsOnly", _errorsOnly },
              { "ordered", IsOrdered },
              { "bypassDocumentValidation", () => _bypassDocumentValidation, _bypassDocumentValidation.HasValue },
              { "comment", Comment, Comment != null },
              { "let", _let, _let != null },
              { "writeConcern", writeConcern, writeConcern != null },
              { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue }
          };
      } 

       

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

      The error output looked like this:

      {{Unhandled exception. MongoDB.Driver.ClientBulkWriteException: An error occurred during bulkWrite operation. See InnerException for more details.
       ---> MongoDB.Driver.MongoCommandException: Command bulkWrite failed: BSON field 'bulkWrite.errorsOnly' is an unknown field..
         at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage) in C:\Users\adrian.chervinchuk\Documents\GitHub\mongo-csharp-driver\src\MongoDB.Driver\Core\WireProtocol\CommandUsingCommandMessageWireProtocol.cs:line 500
         at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.SendMessageAndProcessResponseAsync(CommandRequestMessage message, Int32 responseTo, IConnection connection, CancellationToken cancellationToken) in C:\Users\adrian.chervinchuk\Documents\GitHub\mongo-csharp-driver\src\MongoDB.Driver\Core\WireProtocol\CommandUsingCommandMessageWireProtocol.cs:line 589
         at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken) in C:\Users\adrian.chervinchuk\Documents\GitHub\mongo-csharp-driver\src\MongoDB.Driver\Core\WireProtocol\CommandUsingCommandMessageWireProtocol.cs:line 160
         at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocolAsync[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken) in C:\Users\adrian.chervinchuk\Documents\GitHub\mongo-csharp-driver\src\MongoDB.Driver\Core\Servers\Server.cs:line 583}}

       

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            adrian.chervinchuk1@gmail.com adrian chervinchuk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None