我有关于 MongoDB 的 unwind 操作符。
所以,我有这样的文件。
{
"name": "abc",
"report": {
"_2019": {
"May": {
"_9": {
"DATA": [{
"image": "xyz.png",
"object": true
},
{
"image": "abc.png",
"object": true
}
]
},
"_10": {
"DATA": [{
"image": "ejf.png",
"object": false
},
{
"image": "qwe.png",
"object": false
}
]
}
},
"June": {
"_1": {
"DATA": [{
"image": "jsk.png",
"object": false
}]
}
}
},
"_2020": {
"January": {
"_30": {
"DATA": [{
"image": "hhg.png",
"object": false
}]
}
}
} …Run Code Online (Sandbox Code Playgroud) 我有这样的代码
public async Task<List<User>> GetUsersByField(string fieldName, string fieldValue)
{
var filter = Builders<User>.Filter.Eq(fieldName, fieldValue);
var result = await _usersCollection.Find(filter).ToListAsync();
return result.ToList();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用迭代它时
foreach(var w in GetUsersByField("Name", John"))
Run Code Online (Sandbox Code Playgroud)
它显示错误
"不包含'GetEnumerator'的公共定义"
我试过用
public async IEnumerable<Task<List<User>>> GetUsersByField(string fieldName, string fieldValue)
Run Code Online (Sandbox Code Playgroud)
但仍显示错误.有什么建议?