如何在 F# 中使用 Lookup MongoDB

How use Lookup MongoDB in F#

我在 C# 中有以下内容

var pipe = collection
                .Aggregate()
                .Match(filter)
                .Lookup("entity", "localField", "foreignField", "as");

这要归功于隐式转换,但 F# 不支持隐式转换。如何在 F# 中实现上述内容?

如何执行从字符串到 FieldDefinition 的显式转换?

let pipe = collection.Aggregate().Match(filter).Lookup("", "", "", "")

如果需要,您可以手动调用 FieldDefinition<_>.op_Implicit(fieldName),但 MongoDB 驱动程序实际上有一个名为 StringFieldDefinition 的 class,这稍微容易一些:

let pipe =
    let localField = StringFieldDefinition<_>("localField")
    let foreignField = StringFieldDefinition<_>("foreignField")
    let as' = StringFieldDefinition<_>("as")
    collection
        .Aggregate()
        .Match(fun _ -> true)
        .Lookup("entity", localField, foreignField, as')