[CSHARP-4569] LINQ3 support for bracket notation on Exists Filter not working Created: 15/Mar/23  Updated: 20/Mar/23  Resolved: 20/Mar/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Neil N/A Assignee: Dmitry Lukyanov (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-4562 SortBy failure for dictionary entry i... Closed
Related
is related to CSHARP-4562 SortBy failure for dictionary entry i... Closed
Documentation Changes Summary:

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?


 Description   

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.



 Comments   
Comment by Neil N/A [ 20/Mar/23 ]

@Robert Stam CSHARP-4562 looks pretty much like the same issue I'm having. I think this can be closed since that bug is closed.

Comment by Neil N/A [ 20/Mar/23 ]

Hi, @Dmitry Lukyanov

The temp structure would be more like this:

    public class TempObj
    {
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        [BsonIgnoreIfDefault]
        public string Id { get; set; }
 
        [BsonRequired]
        public int UserId { get; set; }
 
        public CultureDictionary<IEnumerable<UserData>> Sections { get; set; }
    }

where CultureDictionary is a derived classed of IDictionary.

 

Comment by Robert Stam [ 20/Mar/23 ]

This looks related to CSHARP-4562.

Comment by Dmitry Lukyanov (Inactive) [ 20/Mar/23 ]

Hey neil.ong31@gmail.com ,

Thank you for your report. Can you confirm that TempObj structure you use is

    public class TempObj
    {
        public BsonDocument Sections { get; set; }
    } 

?

Generated at Wed Feb 07 21:48:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.