My documents have an array property in them. Lets call it arrayProperty something like this:
{
_id: mongoObjectIdThingy,
arrayProperty: [
{string1: "aString",otherProperty:"somethingelse"},
{string1: "aString2",otherProperty:"somethingelse"}
]
}
I'm using the mongodb c# driver. I want to find all documents that contain any of a list of string1 values. For example say I have a list of strings:
["a","b","aString"]
I want the query to return the above document. I've tried this:
var builder = Builders<MyObject>.Filter;
var listToFind = new List<string>{"a","b","aString"};
return builder.ElemMatch(o => o.arrayProperty,
d => listToFind.Contains(d.string1));
But got this exception:
Unsupported filter: Contains(value(System.Collections.Generic.List`1[System.String]))
It seems like I can't do a contains linq expression in the driver's filter expression. How does one write this type of query in mongoDB with C#?