英文:
InvalidOperationException: ReadName can only be called when State is Name, not when State is EndOfDocument
问题
我在使用MongoDB.Driver版本"2.19.0"时遇到了这个异常。代码如下(其中Configuration是一个子文档):
return await _customerCollection.Find(x => x.CustomerId == id).Project(x => x.Configuration).FirstOrDefaultAsync();
在版本2.18上它只返回null。这是否是Mongo C#驱动程序的一个bug?
英文:
I get that exception when using MongoDB.Driver Version="2.19.0". The code is (Configuration being a subdocument):
return await _customerCollection.Find(x => x.CustomerId == id).Project(x => x.Configuration).FirstOrDefaultAsync();
On Version 2.18 it just returns null. Is this a bug in the Mongo C# driver?
答案1
得分: 1
这个问题我也遇到过,看起来在2.19.2版本中已修复。
英文:
I had the same issue, this appears to be fixed in 2.19.2
答案2
得分: 0
异常仅对没有 Configuration 的客户文档抛出。但由于在 2.18 版本中没有发生这种情况,我认为这是在 2.19 中引入的 MongoDB.Driver 错误。
目前,我已将代码更改为:
var customer = await _customerCollection.Find(x => x.CustomerId == id).FirstOrDefaultAsync();
return customer?.Configuration;
英文:
The exception is thrown only for Customer documents that don't have a Configuration. Still, since it didn't happen in 2.18 I suppose this is a MongoDB.Driver bug introduced in 2.19.
At the moment I changed the code to:
var customer = await _customerCollection.Find(x => x.CustomerId == id).FirstOrDefaultAsync();
return customer?.Configuration;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论