c# - 尽管没有进行算术运算,但 IMongoCollection<T>.UpdateOneAsync 中出现 OverflowException

标签 c# mongodb

我遇到了 '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。

在这里检查:http://docs.mongodb.org/manual/reference/bson-types/

关于c# - 尽管没有进行算术运算,但 IMongoCollection<T>.UpdateOneAsync 中出现 OverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32018073/

相关文章:

mongodb - 服务器在 SASL 身份验证步骤 : Authentication failed 上返回错误

c# - 使用 Autofac 的 Windows 服务保留引用

当reduce函数不使用emit中的变量时,MongoDB MapReduce出现奇怪的值

c# - 将 .NET ArrayList 编码到 VB6 [Com interop]

c# - 如何为 HttpWebRequest 设置 HttpRequestHeader?

javascript - 如何将页面添加到现有的 AngularJS 应用程序?

python - 使用模拟 MongoDB 服务器进行单元测试

javascript - 蒙哥错误: failed to connect to server [localhost:27017]

c# - 针对 ActiveDirectory 进行身份验证

c# - 选择工作簿 Excel 已使用按钮单击方法打开