IQueryable<T> on mongoDB '$project 或 $group 不支持 {document}

IQueryable<T> on mongoDB '$project or $group does not support {document}

在 IQueryable

运行 Select 之后我遇到了这个问题

'$project or $group does not support {document}.'

public Interface IVideo
{
   ....
   public string File { get; set;} 
   public bool Categorized { get; set;}
   public IMovie Movie { get; set;} 
   ....
}

public Interface IMovie
{
   ....
   public List<string> Langauge {get; set;} 
   ....
}

public static Dictionary<string, int> GetLanguage(string isp)
{
    //Repository.GetVideos() is IQueryable<IVideo>
    var videos = Repository.GetVideos().Where(q => q.Categorized && (
                                                       q.File == isp ||
                                                       q.File == "st"));

    var language = videos.SelectMany(q => q.Movie.Language).Select(e => e);
    var ql = from x in language
        group x by x
        into g
        let count = g.Count()
        orderby count descending
        select new {g.Key, count}; // issue is here

    return ql.ToDictionary(item => item.Key, item => item.count);
}

我该如何解决这个问题?

找到修复

因为 MongoDB 不支持分组或投影,仅列出可用语言

public static Dictionary<string, int> GetLanguage(string isp)
{
    //Repository.GetVideos() is IQueryable<IVideo>
    var videos = Repository.GetVideos().Where(q => q.Categorized && (
                                                       q.File == isp ||
                                                       q.File == "st"));
    //ToList() added here
    var language = videos.SelectMany(q => q.Movie.Language).Select(e => e).ToList();
    var ql = from x in language
        group x by x
        into g
        let count = g.Count()
        orderby count descending
        select new {g.Key, count}; 

    return ql.ToDictionary(item => item.Key, item => item.count);
}