MongoDb c# driver find item in array by field value

后端 未结 4 1120
再見小時候
再見小時候 2020-12-14 01:20

i found the way to check is the value contains in simple array :

var filter = Builders.Filter.AnyEq(x => x.Tags, \"mongodb\");
4条回答
  •  醉酒成梦
    2020-12-14 01:22

    You need the $elemMatch operator. You could use Builders.Filter.ElemMatch or an Any expression:

    Find(x => x.Tags.Any(t => t.Name == "test")).ToListAsync()
    

    http://mongodb.github.io/mongo-csharp-driver/2.0/reference/driver/expressions/#elemmatch

提交回复
热议问题