【问题标题】:IQueryable<T> on mongoDB '$project or $group does not support {document}mongoDB '$project 或 $group 上的 IQueryable<T> 不支持 {document}
【发布时间】:2022-01-23 17:43:46
【问题描述】:

在 IQueryable 上运行 Select 后我遇到了这个问题

'$project 或 $group 不支持 {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);
}

我该如何解决这个问题?

【问题讨论】:

    标签: c# mongodb iqueryable


    【解决方案1】:

    找到解决办法

    由于 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);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      相关资源
      最近更新 更多