Search code examples
mongodbmongodb-.net-driver

Does Mongo C# Driver not support Count for collections?


I'm working with MongoDb C# Driver and I have the collection that I show below. I want to order by Rating.Count like show in the LINQ Query but I reveive the same error:

Unable to determine the serialization information for the expression: a.Rating.Count.

Does Mongo C# Driver not support Count for collections?

activities => activities.OrderByDescending(a => a.Rating.Count)

    {
      "_id" : "5171243a3814fe1fb0bfbad6",
      "Verb" : "post",
      "Url" : null,
      "Title" : "posted a new question",
      "Content" : "mongodb and redis",
      "Icon" : null,
      "Tags" : ["mongodb", "redis"],
      "Rating" : [{
          "UserId" : "516be7913814fe2b0cc123c4",
          "Value" : 1
      }]
}

Thanks in advance!!!


Solution

  • It's unfortunate that the error message is not more helpful, but the root cause is that MongoDB does not support sorting the returned documents by the size of an array field.

    We are working on a new version of our LINQ support. The primary goal of the new version is to support mapping LINQ queries to aggregation framework pipelines, but another goal is to improve error messages.