从mongo样本来看,我们有这样一个集合;
{ "_id" : 1, "semester" : 1, "grades" : [ 70, 87, 90 ] }
{ "_id" : 2, "semester" : 1, "grades" : [ 90, 88, 92 ] }
{ "_id" : 3, "semester" : 1, "grades" : [ 85, 100, 90 ] }
{ "_id" : 4, "semester" : 2, "grades" : [ 79, 85, 80 ] }
{ "_id" : 5, "semester" : 2, "grades" : [ 88, 88, 92 ] }
{ "_id" : 6, "semester" : 2, "grades" : [ 95, 90, 96 ] }
db.students.find( { semester: 1, grades: { $gte: 85 } },
{ "grades.$": 1 } )
这是什么导致的;
{ "_id" : 1, "grades" : [ 87 ] }
{ "_id" : 2, "grades" : [ 90 ] }
{ "_id" : 3, "grades" : [ 85 ] }
{"grades": [87, 90, 85]}
在一个阵列上。
var result = collectionServerName.Find(x => x.LogList.Any(p => p.Ip.Contains("192")))
.Project(Builders<ServerName>.Projection.Exclude("_id").Include("LogList"))
.ToList();
我尝试了以下代码;
var result = collectionServerName.Find(x => x.LogList.Any(p => p.Ip.Contains("192"))).Project(t => t.LogList.SelectMany(k => k)).ToList();
但它给了我以下编译错误
选择多个
The type arguments for method 'Enumerable.SelectMany<TSource, TResult>(IEnumerable<TSource>, Func<TSource, IEnumerable<TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
如果我只使用Select;
var result = collectionServerName.Find(x => x.LogList.Any(p => p.Ip.Contains("192"))).Project(t => t.LogList.Select(k => k)).ToList();
结果类型为
List<IEnumarable<Log>>
我之所以需要作为一个数组,是因为我必须在检索结果之前对其进行分页。我正在使用c。任何帮助都将不胜感激。