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}}