Here is document structure
{
"_id" : ObjectId("6284f3eceae4fd4c3cfebb39"),
"Codes" : [
"Code 1",
"Code 2",
"Code 3"
]
}
Also i have mongo query which works as expected
{ "Codes" : { "$elemMatch" : { "$regex" : /code/, $options: 'si' } } }
But when i tried to write C# code with mongodb driver
var filter = Builders<MyClass>.Filter
.ElemMatch(x => x.Codes,
Builders<string>.Filter.Regex(c => c, new BsonRegularExpression($"/^{codeFilter}/is")));
and execute this filter definition i've got an exception
System.InvalidOperationException: 'Unable to determine the serialization information for c => c.'
Where is my mistake? How can i create filter definition to check string array items with $regex operator?