我得到这个问题后运行选择IQueryable
“$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);
}
如何解决此问题?
找到修复程序了
因为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);
}