出现错误"歧义鉴别符'revamp@904"从MongoDB在f#(使用c#库)

本文关键字:quot 使用 MongoDB 歧义 错误 鉴别 revamp@904 | 更新日期: 2023-09-27 18:17:16

我试图使用MongoDB为我缓存一些数据,但我似乎无法获得代码返回特定集合。我可以得到其他集合没有问题,但对于这个不能得到它的工作,我不知道为什么。我得到的唯一错误是:

歧义鉴别符'revamp@904'

我已经搜索了很长时间,很难任何迹象表明这是什么意思。下面是我使用的代码:

let GetCacheDataObject ctxName cacheName collection = 
    let ctx = new DataContext(ctxName)
    let q = Query.EQ("CacheName", BsonValue.Create(cacheName.ToString()))
    let entity =
        match ctx.Db.CollectionExists(collection) with
        | false -> null
        | _ -> ctx.Db.GetCollection(typeof<DataObject>, collection).FindOneAs<DataObject>(q)
    entity

一旦找到'FindAsOne',就会抛出这个错误。

DataObject是一个非常基本的用于保存数据的自定义对象。定义如下:

public class DataObject:IHaveIdentifier
{
    public BsonObjectId _id { get; set; }
    //public long Id { get; set; }
    public string[] Columns { get; set; }
    public IEnumerable<object[]> Rows { get; set; }
    public string CacheName { get; set; }
    public int GetColumnIndex(string column)
    {
        for (int i = 0; i < this.Columns.Length; i++)
            if (this.Columns[i] == column)
                return i;
        return -1;
    }
}

IHaveIdentifier接口是非常基本的:

public interface IHaveIdentifier
{
    BsonObjectId _id { get; set; }
}

下面是最初用于保存数据的代码:

member x.Save<'T when 'T :> IHaveIdentifier>(entity:'T, collection:string) =
        if (entity._id = null ) then x.Insert<'T>(entity, collection)
        else
            x.Delete(entity, collection)
            x.Insert<'T>(entity, collection)
        x.VerifyNoErrors()
let CacheDataObject<'T when 'T :> IHaveIdentifier>(entity:'T, ctxName, collection) =
    let ctx = new DataContext(ctxName)
    ctx.Save(entity, collection)

这段代码前几天还在工作,然后发生了变化,我似乎不知道发生了什么。

更新:在

出现错误"歧义鉴别符'revamp@904"从MongoDB在f#(使用c#库)

上面添加了初始保存代码

是否可以在mongo shell中运行相同的查询,看看现有文档是什么样子的

我的怀疑是它有一个"_t"值导致问题。如果是这样,问题不在于FindOne,而在于文档最初是如何保存的,所以我们可能需要进一步回顾并查看。

Brian和Robert,你的意见帮助我弄清楚了到底发生了什么。我能够确定IEnumberable Rows属性正是问题所在。我将行设置为seq。在f#中,Seq是惰性求值的,在这种情况下,这意味着行被设置为函数的输出值(有点像ref),而不是实际结果。一旦我转换行使用Seq。ToArray,然后一切正常

非常感谢你们为我指明了正确的道路。

相关文章: