Summary
When a saved string starts with an accented character is being searched with the same word, it will not find the results corresponding to the searched expression.
The issue only happens when the searched value and the searching value are both start with an accented character.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
MongoDB Driver - 2.22
MongoDB server - 5.0.10
LINQ - 4.3.0
.NET 7.0
How to Reproduce
In a collection there are documents with a Name property which is a string.
Some of the documents has their Name's set to "Ügyfél" - the important thing here is the starting character, which is accented.
When I'm trying to find across the documents the ones which has "Ügyfél" in their Name's:
string[] names = new string[] { "Ügyfél" }; return *collection*.AsQueryable().Where( c => names.Any( n => c.Name.Contains( n ) ) );
The result will be an empty list. - Doesn't work.
When I'm trying to find across the documents the ones which has "gyfél" in their Name's:
string[] names = new string[] { "gyfél" }; return *collection*.AsQueryable().Where( c => names.Any( n => c.Name.Contains( n ) ) );
The result will be all the documents which has "gyfél" in their Name's, therefore the ones with "Ügyfél". - Works fine.
When I'm trying to find across the documents the ones which has "él" in their Name's:
string[] names = new string[] { "él" }; return *collection*.AsQueryable().Where( c => names.Any( n => c.Name.Contains( n ) ) );
The result will be all the documents which has "él" in their Name's, therefore the ones with "Ügyfél". - Works fine.
If I'm using LINQ Expression:
ParameterExpression argParam = Expression.Parameter( typeof( EventModel ), "eventmodel" ); Expression result = null; string[] names = new string[] { "Ügyfél" }; foreach( string name in names ) { Expression<Func<EventModel, bool>> anyExpr = eventModel => eventModel.Name.Contains( name ); anyExpr = Expression.Lambda<Func<EventModel, bool>>( anyExpr.Body.Replace( anyExpr.Parameters[0], argParam ), argParam ); if( result == null ) result = anyExpr.Body; else result = Expression.AndAlso( result, anyExpr.Body ); }if( result is not null ) { Expression<Func<EventModel, bool>> finalExpression = Expression.Lambda<Func<EventModel, bool>>( result, argParam ); return source.Where( finalExpression ); }
The result will be all the documents which has "Ügyfél" in their Name's. - Works fine.
Additional Background
The actual query which is being built by the concatenated LINQ is:
{"$match":{"$expr":{"$anyElementTrue":{"$map":{"input": ["Ügyfél"],"as":"n","in":{"$gte":[{"$indexOfCP": ["$Name","$$n"]},0]}}}}}}
While the Expression LINQ builds the following:
{"$match":{"Name": /Ügyfél/is}}