Ada*_*rsh 3 .net c# mongodb mongodb-csharp-2.0 mongodb-.net-driver
当字段以字符串数组的形式给出时,您如何在新的 MongoDB C# 驱动程序中对字段进行投影?我可以找到在单个领域进行投影的方法
collection.find(filter).Project(Builders<Category>.Projection.Include(fieldName)
我如何扩展它以获取一系列字段?。
还有扩展方法 Include
var projection = Builders<Category>.Projection.Include(fieldList.First());
foreach (var field in fieldList.Skip(1))
{
projection = projection.Include(field);
}
var result = await collection.Find(filter).Project(projection).ToListAsync();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7511 次 |
| 最近记录: |