InvalidOperationException: ReadName只能在State为Name时调用,不能在State为EndOfDocument时调用

问题描述 投票:0回答:1

我在使用 MongoDB.Driver Version="2.19.0" 时遇到异常。代码是(配置是一个子文档):

return await _customerCollection.Find(x => x.CustomerId == id).Project(x => x.Configuration).FirstOrDefaultAsync();

在 2.18 版中它只返回 null。这是 Mongo C# 驱动程序中的错误吗?

c# mongodb mongodb-.net-driver
1个回答
0
投票

仅针对没有配置的客户文档抛出异常。不过,由于它没有在 2.18 中发生,我想这是 2.19 中引入的 MongoDB.Driver 错误。

此刻我将代码更改为:

var customer = await _customerCollection.Find(x => x.CustomerId == id).FirstOrDefaultAsync(); 
return customer?.Configuration;
© www.soinside.com 2019 - 2024. All rights reserved.