我正在使用mongodb驱动程序访问我的数据库.net核心web api。
我有这个文件的结构
{
"_id" : 1,
"ParticipantIdentities" : [
{
"ParticipantId" : 1,
"Player" : {
"AccountId" : 45678945,
"AnotherProps" :"values"
}
}
[Another arrays items]
}
我想使用object.ParticipantIdentities.Player.AccountId
来装修
我试过这种方式
var filter = Builders<Match>.Filter.Where(e => e.ParticipantIdentities.Where(p => p.Player.AccountId == AccountId).Count() > 1);
var result = await _context.Matches.Find(filter).ToListAsync();
它抛出一个异常,说不支持.Count()。 我还在使用mongodb查询noob。
提前致谢。
答案 0 :(得分:2)
您需要做的就是
var filter = Builders<Match>.Filter.Eq("ParticipantIdentities.Player.AccountId", accountId);