My documents have an array property in them. Lets call it arrayProperty something like this:
{
_id: mongoObjectIdThingy,
arrayProperty: [
{string1:
I believe you are looking for the In
FilterDefinition, which would make your Builder look like this;
return Builders<MyObject>.Filter.ElemMatch(
o => o.arrayProperty,
Builders<ArrayProperty>.Filter.In(y => y.string1, listToFind));
This builds this query
db.MyObject.find({ "arrayProperty" : { "$elemMatch" : { "string1" : { "$in" : ["a", "b", "aString"] } } } })
To be able to use the Regex you would have to build a different query (I'm not on coffee so this is without any warranty)
var listToFind = new List<string> { "a", "b", "astring" };
var regexList = listToFind.Select(x => new BsonRegularExpression(x, "i"));
var filterList = new List<FilterDefinition<MyObject>>();
foreach (var bsonRegularExpression in regexList)
{
FilterDefinition<MyObject> fil = Builders<MyObject>.Filter.ElemMatch(o => o.arrayProperty, Builders<ArrayProperty>.Filter.Regex(
x => x.string1,
bsonRegularExpression));
filterList.Add(fil);
}
var orFilter = Builders<MyObject>.Filter.Or(filterList);
var result = collection.Find(orFilter).ToList();
Which builds the follow query
db.MyObject.find({ "$or" : [{ "arrayProperty" : { "$elemMatch" : { "string1" : /a/i } } }, { "arrayProperty" : { "$elemMatch" : { "string1" : /b/i } } }, { "arrayProperty" : { "$elemMatch" : { "string1" : /astring/i } } }] })