-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 2.7.0
-
Component/s: None
-
None
-
Environment:Windows 10 64-bit, MongoDB 4.0.0-rc1, .NET Core 2.1
I am using the C# driver 2.7.0-beta0001 and MongoDB 4.0.0-rc1 server and I am trying to update multiple documents on a single replica set server using the new transaction feature and I always get an exception:
MongoDB.Driver.MongoCommandException: Command update failed: BSON field 'OperationSessionInfo.txnNumber' is a duplicate field.
at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage)
at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocolAsync[TResult](IWireProtocol`1 protocol, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.RetryableWriteOperationExecutor.ExecuteAsync[TResult](IRetryableWriteOperation`1 operation, RetryableWriteContext context, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.ExecuteBatchAsync(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.ExecuteBatchesAsync(RetryableWriteContext context, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.ExecuteBatchAsync(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
at MongoDB.Driver.OperationExecutor.ExecuteWriteOperationAsync[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperationAsync[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.BulkWriteAsync(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionBase`1.UpdateOneAsync(FilterDefinition`1 filter, UpdateDefinition`1 update, UpdateOptions options, Func`3 bulkWriteAsync)
Here is my code:
var client = new MongoClient(ConnectionString); var database = client.GetDatabase(DatabaseName); var Coupons = database.GetCollection<Coupon>("Coupons"); var Books = database.GetCollection<Book>("Books"); var session = await database.Client.StartSessionAsync(); session.StartTransaction(); try { Coupons.UpdateOneAsync(session, couponsFilter, couponsUpdate);//Exception happens at this line Books.UpdateOneAsync(session, booksFilter, booksUpdate); await session.CommitTransactionAsync(); } catch (Exception ex) { await session.AbortTransactionAsync(); Console.WriteLine(ex.StackTrace); }