I am using the C# driver for Mongodb and I was wondering how to find any documents with an ID (int) that correspond to a list of IDs(List).
I know theoretically, if I was checking a list in each document for a single int I could use "EqAny(c=>c.IDs, 32)" however I am looking for the opposite of that where I can check a single int on the document to see if it matches with any of a list of ints.
My current code is this, which returns all documents due to the line "var filter = FilterDefinition.Empty;"
public void GetSerialsForZones(List<int> zoneIds)
{
IMongoDatabase db = MongoClient.GetDatabase(DatabaseName);
IMongoCollection<ZoneMessage> collection = db.GetCollection<ZoneMessage>(CollectionName);
var filter = FilterDefinition<ZoneMessage>.Empty;
foreach (int zoneId in zoneIds)
filter &= Builders<ZoneMessage>.Filter.Eq(c => c.ID, zoneId);
var result = await collection.Find(filter).ToListAsync();
}
The code has been modified for simplification.