Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4842

String field starting with accented character can't be found by concatenated LINQ.

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.22.0
    • Component/s: Linq
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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}}

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            89.t.robert@gmail.com Takács Róbert
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: