gpt4 book ai didi

c# - MongoDb 如何查找具有无效数据的元素

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:17 24 4
gpt4 key购买 nike

我有一个非常大的 mongo 数据库集合。

现在,一项任务繁多的夜间工作只有一项任务要运行。

代码像这样用 foreach 运行:

var sets = Collection.FindAll();
await sets.ForEachAsync(handler)

今天早上我得到了:

System.FormatException: An error occurred while deserializing the Connections property of class SR.BusPortal.DomainModel.Search.StoredConnectionSet: An error occurred while deserializing the DeepLinkToken property of class SR.BusPortal.DomainModel.Search.StoredConnectionStep: Invalid BsonType: 34.

错误相关的属性定义如下:

 [IgnoreNull]
[DataMember(Order = 1390, Name = "lt")]
public string[] DeepLinkToken { get; set; }

这个数组中是否有任何可能有问题的特殊字符串?

现在如何找出哪个文档具有无效属性?它的值(value)是多少?有没有办法选择它?例如使用 mongo chef 还是 c# api?

一个想法是将所有内容读取为 BsonDocuments,然后手动反序列化它们 BsonSerializer.Deserialize<MyType>(doc); .但是有更好的方法吗?

更新我创建了一个小型测试工具,但没有出现任何异常。在考虑以下代码应该在特定文档上中断/抛出时,我是否犯了错误?或者它更有可能只是一个临时错误?

source.FindAll(options).ForEachAsync((doc, pos) =>
{
try
{
var element = BsonSerializer.Deserialize<StoredConnectionSet>(doc);
}
catch(Exception err)
{
if(Debugger.IsAttached) // I run in debug with an attached VS debugger
{
Debugger.Break();
}

Console.WriteLine(err);
throw;
}
})

最佳答案

我发现它与数据无关。它与有时发生的一些连接问题有关。

不确定为什么会出现此异常,但解决连接问题解决了此错误。

关于c# - MongoDb 如何查找具有无效数据的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36390507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com