MongoDB c#错误UpdateOne,ReplaceOne和DeleteMany

时间:2019-10-08 19:13:14

标签: c# mongodb

尝试执行以下任何命令(UpdateOne,ReplaceOne和DeleteMany)时出现重复错误

  

MongoDB.Driver.MongoConnectionException HResult = 0x80131500
  Mensaje =打开与主机的连接时发生异常   服务器。 Origen = MongoDB.Driver.Core德拉皮拉城:zh   MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken   cancelToken)zh   MongoDB.Driver.Core.Connections.BinaryConnection.Open(CancellationToken   cancelToken)zh   MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquiredConnection.Open(CancellationToken   cancelToken)zh   MongoDB.Driver.Core.Servers.Server.GetChannel(CancellationToken   cancelToken)zh   MongoDB.Driver.Core.Bindings.ServerChannelSource.GetChannel(CancellationToken   cancelToken)zh   MongoDB.Driver.Core.Bindings.ChannelSourceHandle.GetChannel(CancellationToken   cancelToken)zh   MongoDB.Driver.Core.Operations.RetryableWriteContext.Create(IWriteBinding   绑定,布尔值retryRequested,CancellationToken cancelledToken)   恩   MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Execute(IWriteBinding   绑定,CancellationToken cancelToken()   MongoDB.Driver.OperationExecutor.ExecuteWriteOperation [TResult](IWriteBinding   绑定,IWriteOperation 1 operation, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionImpl 1.ExecuteWriteOperation [TResult](IClientSessionHandle   会话,IWriteOperation 1 operation, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionImpl 1.BulkWrite(IClientSessionHandle   会话,即IEnumerable 1 requests, BulkWriteOptions options, CancellationToken cancellationToken) en MongoDB.Driver.MongoCollectionImpl 1。<> c__DisplayClass23_0.b__0(IClientSessionHandle   会议)   MongoDB.Driver.MongoCollectionImpl 1.UsingImplicitSession[TResult](Func 2   func,CancellationToken cancelToken()   MongoDB.Driver.MongoCollectionImpl 1.BulkWrite(IEnumerable 1个请求,   BulkWriteOptions选项,CancellationToken cancelToken(en)   MongoDB.Driver.MongoCollectionBase 1.<>c__DisplayClass94_0.<UpdateOne>b__0(IEnumerable 1   请求,BulkWriteOptions bulkWriteOptions)zh-cn   MongoDB.Driver.MongoCollectionBase 1.UpdateOne(FilterDefinition 1   过滤器,UpdateDefinition 1 update, UpdateOptions options, Func 3   bulkWrite)zh   MongoDB.Driver.MongoCollectionBase 1.UpdateOne(FilterDefinition 1   过滤器,UpdateDefinition 1 update, UpdateOptions options, CancellationToken cancellationToken) en DataManager.UpdateElements.<>c__DisplayClass86_0.<UpdateTransferSwitches>b__0(TransferSwitch en System.Threading.Tasks.Parallel.<>c__DisplayClass31_0 2.b__0(Int32   我)   System.Threading.Tasks.Parallel。<> c__DisplayClass17_0`1.b__1()

并行崩溃的代码行。 ForEach(),在类方法中

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);
在其他类方法中的

是DeleteMany

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

和ReplaceOne处于相同的方法和相同的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 });
                }

我该如何解决这些错误?

更新 为此,我使用2.1版本的mongoDB.Driver

0 个答案:

没有答案