Search code examples
c#mongodbmongodb-.net-drivermongodb-csharp-2.0

MongoDb c# driver 2.0 Any in many to many


I have the following issue - how to check is there are any element from int array mailListIds contains in MailLists in MailListId field. I think it could be something like the following :

Builders<Profile>.Filter.AnyIn(p => p.MailLists.Select(m => m.MailListId), mailListIds)

But that code cannot be serialized into query. How to implement it ?


Solution

  • I've solved the problem by the following way :

     Builders<Profile>.Filter.Where(p => p.MailLists.Any(b => mailListIds.Contains(b.MailListId)))