I want to use LINQ to return all records in a MongoDB collection where the field in the record is a list of strings and any string in the list matches any string value in a list of strings used as the search criteria:
Mongo Record in Collection ("Item"):
{
"_id": ...,
"StringList": [
"string1",
"string2",
"string3"
],
...
}
Search Criteria:
var criteria = new List<string> { "string2", "string4" };
My Code:
var foundItems = iMongoDataProvider.FindAll<Item>()
.Where(x =>x.StringList.ContainsAny(criteria)).ToList();
Based on the above, the Mongo record should be returned since one of the StringList values matches one of the values in the search criteria. Nothing is returned even though I can manually peruse the collection and find the matching record. What am I doing wrong? Can someone provide an example that will do what I need? Thanks!