最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

arrays - C# MongoDB AllMatchingElements Expression not supported - Stack Overflow

programmeradmin6浏览0评论

I'm trying to update the subArray elements by the key, adding the value. I'm using the latest version of the library. In the new approach, the "AllMatchingElements" method is used. It seems like I'm doing everything according to the manual, but as a result of the execution, I get "Expression not supported" - what's the problem?

public async Task AddCupPass(Guid cupId, List<string> rank)
{
    var u = Builders<CupStat>.Update.Inc(f => f.Winners.AllMatchingElements("winnerId").Value, 1);
    
    var arrayFilterDefinitions = new List<ArrayFilterDefinition>();
    arrayFilterDefinitions.Add(new BsonDocumentArrayFilterDefinition<CupStat>(new BsonDocument("winnerId.key", rank.First())));
    
    await _cupStatColl.UpdateOneAsync(c => c.Id == cupId, u, new UpdateOptions
    {
        ArrayFilters = arrayFilterDefinitions,
    });
}

public class CupStat
{
    public Guid Id { get; set; }
    public Dictionary<string, int> Winners { get; set; } = [];
}
发布评论

评论列表(0)

  1. 暂无评论