MongoDB oData support

I am using MongoDB c# driver 2.10 together with asp.net core data 7.2.
however when I am trying to use the Query Option $apply like
https://localhost:44381/odata/Photos?$apply=groupby((Path))
I got the exception of 'Value type of serializer is System.String and does not match member type System.Object.

After digging deeper, I found MongoDriver’s PipelineBinder is trying to bind a object of below:

.New Microsoft.AspNet.OData.Query.Expressions.GroupByWrapper(){
    GroupByContainer = .New Microsoft.AspNet.OData.Query.Expressions.AggregationPropertyContainer+LastInChain(){
        Name = "path",
        Value = $$it.Path
    }
}

But this object is not a simple property of my entity, so the driver failed to bind it.
Is it a bug in MongoDriver supporting oData expression?

Appreciate this issue is now around 4 years old, but I’m experiencing exactly the same issue.

Mongo .NET driver version: 2.24.0
.NET version: 7.0
Microsoft.OData.Core: 7.21.0
Microsoft.AspNetCore.OData: 8.2.3

Expanding on the observations from @Yan_Wenwei, the issue seems be related to the fact that $it. within the generated expression is always of type System.Object, regardless of the underlying type that is being aggregated.

The Mongo code that processes this expression tree looks to dynamically generate class and member maps, and fails when attempting to set the serializer of the dynamically generated member map for $it. due to types not matching. See mongo-csharp-driver/src/MongoDB.Bson/Serialization/BsonMemberMap.cs at b2b672550cf7a523c234b9657ab5e9694c31726b · mongodb/mongo-csharp-driver · GitHub.

Surprised to see this issue still around, and I wonder what I might be missing. Has anyone else come across this and found a workaround?

Thanks.

I’ve also just run into this exact issue. Don’t suppose anybody has a fix?

Hi,

We unfortunately don’t support the $apply operator in OData yet. I’ve filed a ticket for this request here. This would be something we will look into addressing in the MongoDB OData extension package.

Thanks,

Rishit.