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

LINQ3 support for bracket notation on Exists Filter not working

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • 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 upgrading to version 2.19 we noticed that our 'exists' filters were breaking and throwing an error message. We believe that this may be an issue with the way LINQ3 handles the filter.

      Below is the error message it spits out at us when we try to use a string variable as a key using bracket notation. It should be noted that this was working when first written using MongoDB.Driver version 2.14.1 and still works if we revert the version.

      
      

      MongoDB.Driver.Linq.ExpressionNotSupportedException : Expression must be a constant:

      For our codebase we create a filter definition like this: 

      Builders<TempObj>.Filter.Exists(t => t.Sections[cultureCode]) 

       

      Where we get passed a string called "cultureCode" that contains the key for the Sections object. We must pass the key name as a parameter since Sections is an object that can have either one or up to 20+ different keys that we do not know at compile time.

      An example of the object being store within Mongo would be like:

      {
        Name: "Temp",
        Sections: {
          "en-US": {},
          "en-CA": {},
          ...
        }
      },
      {
      Name: "Temp",
      Sections: {
         "en-US": {},
        }
      },

       

       

       

      How to Reproduce

      Try to use a filter definition like this using bracket notation.

      Builders<TempObj>.Filter.Exists(t => t.Sections[cultureCode]) 

      Additional Background

      I don't have much extra to put here, but if further details are needed I can try and provide them.

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            neil.ong31@gmail.com Neil N/A
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: