我遇到了 'System.OverflowException' in MongoDB.Bson.dll
( Additional information: Arithmetic operation resulted in an overflow.
),当调用 UpdateOneAsync
时不知道为什么:
CarSpec spec = GetSpec();
var updateDefinition = Builders<Cars>.Update.Set(c => c.Spec, spec);
IMongoCollection<CarBatch> carsBatch = GetCarsBatch();
var result = await carsBatch.UpdateOneAsync(c => c.Id == car.Id, updateDefinition);
这些是重要的数据结构:
public class Car {
public string Id;
public ServiceVersion CurrentVersion = new ServiceVersion();
public CarSpec Spec = new CarSpec();
public List<StatusNotice> StatusNotifications = new List<StatusNotice>();
}
public class CarSpec {
internal const uint InitialChasisNumber = 1000000000;
public uint ChasisNumber = InitialChasisNumber;
public uint DoorsCount;
}
可能出了什么问题?
最佳答案
没有与 uint 数据类型相关的东西吗?尝试更新为 int 并告诉我们结果。
正如您在 MongoDB 文档中看到的,支持的可用 BSON 类型不包括 uint32。
关于c# - 尽管没有进行算术运算,但 IMongoCollection<T>.UpdateOneAsync 中出现 OverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32018073/