I want to find documents using the elementMatch operator (or something that works better).
Example:
{
"_id": "1",
"messages": [
"foo A",
"bar B"
]
},
{
"_id": "2",
"messages": [
"bar B"
]
}
I want to find all documents where the string foo
is contained in any string in the messages
array.
I am trying to make the syntax work using the BsonDocument
syntax in C#. I do not have C# models, only BsonDocument/BsonValue.
Something like:
var Filter = Builders<BsonDocument>.Filter;
var ItemFilter = Builders<BsonValue>.Filter;
var result = await collection.FindAsync(FindFilter.ElemMatch<BsonValue>("messages", ItemFilter.???));
How would this work? Given the documents above, this should return the first document with id=1, because its messages array contains at least one string that contains “foo”.
Thanks for helping out.