Error UpdateOne, ReplaceOne and DeleteMany with MongoDB c#

0

Repetitive errors when trying to execute any of these commands, UpdateOne, ReplaceOne and DeleteMany

MongoDB.Driver.MongoConnectionException HResult=0x80131500
Mensaje = An exception occurred while opening a connection to the server. Origen = MongoDB.Driver.Core Seguimiento de la pila: en MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken cancellationToken) en MongoDB.Driver.Core.Connections.BinaryConnection.Open(CancellationToken cancellationToken) en MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquiredConnection.Open(CancellationToken cancellationToken) en MongoDB.Driver.Core.Servers.Server.GetChannel(CancellationToken cancellationToken) en MongoDB.Driver.Core.Bindings.ServerChannelSource.GetChannel(CancellationToken cancellationToken) en MongoDB.Driver.Core.Bindings.ChannelSourceHandle.GetChannel(CancellationToken cancellationToken) en MongoDB.Driver.Core.Operations.RetryableWriteContext.Create(IWriteBinding binding, Boolean retryRequested, CancellationToken cancellationToken) en MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken) en MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation1 operation, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionImpl1.ExecuteWriteOperation[TResult](IClientSessionHandle session, IWriteOperation1 operation, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionImpl1.BulkWrite(IClientSessionHandle session, IEnumerable1 requests, BulkWriteOptions options, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionImpl1.<>c__DisplayClass23_0.b__0(IClientSessionHandle session) en MongoDB.Driver.MongoCollectionImpl1.UsingImplicitSession[TResult](Func2 func, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionImpl1.BulkWrite(IEnumerable1 requests, BulkWriteOptions options, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionBase1.<>c__DisplayClass94_0.<UpdateOne>b__0(IEnumerable1 requests, BulkWriteOptions bulkWriteOptions) en MongoDB.Driver.MongoCollectionBase1.UpdateOne(FilterDefinition1 filter, UpdateDefinition1 update, UpdateOptions options, Func3 bulkWrite) en MongoDB.Driver.MongoCollectionBase1.UpdateOne(FilterDefinition1 filter, UpdateDefinition1 update, UpdateOptions options, CancellationToken cancellationToken) en DataManager.UpdateElements.<>c__DisplayClass86_0.<UpdateTransferSwitches>b__0(TransferSwitch en System.Threading.Tasks.Parallel.<>c__DisplayClass31_02.b__0(Int32 i) en System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.b__1()

the line of code that crashes in a parallel. ForEach (), in a class method

var BsonData = new BsonDocument
                    {
                        {"ICurrent", Math.Round(transferSwitch.ICurrent,1)},
                        {"Load", load},
                    };
                var filterId = new BsonDocument("_id", transferSwitch.Id);
                var updateTransferSwitch = new BsonDocument("$set", BsonData);
                transferSwitchesCollection.UpdateOne(filterId, updateTransferSwitch);

in other class method is the DeleteMany

var filterDelete = Builders<BsonDocument>.Filter.Not(Builders<BsonDocument>.Filter.Eq("GUIDUpdate", guidUpdate));
                    maintenancesCollection.DeleteMany(filterDelete);

and the ReplaceOne is in the same method and same Parallel.ForEach

                if (maintenance.Value.Show)
                {
                    maintenance.Value.GUIDUpdate = guidUpdate;
                    var filterId = new BsonDocument("_id", maintenance.Value.Id);
                    var bsonData = maintenance.Value.ToBsonDocument();

                    maintenancesCollection.ReplaceOne(filterId, bsonData, new UpdateOptions { IsUpsert = true });
                }

how can I fix those errors?

Update For this I use the 2.1 Version of mongoDB.Driver

c#
mongodb
asked on Stack Overflow Oct 8, 2019 by ger • edited Oct 9, 2019 by ger

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0