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

In a filter Any with array constant and predicate comparing item to field should translate to $in

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.0, 3.2.1
    • Component/s: LINQ3
    • None
    • None
    • Dotnet Drivers
    • 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?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      When making a linq query, where you try to match a value that is a string in c# but has the attribute [BsonRepresentation(BsonType.ObjectId)] against an array of string, then you get the error: "Expression not supported: (fId == f.Id) because the two arguments are serialized differently" It was not an issue before version 3.2.0

      How to Reproduce

      If you have the model

      public class Test
      {
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        public string? Id { get; set; }
      }

      And you then run a find like:

      var client = new MongoClient();
      var mongoDatabase = client.GetDatabase("Test");
      var collection = mongoDatabase.GetCollection<Test>("Test");
      
      var array = new string[] { "67b6f6aea9e81c51180d8668" };
      await collection.Find(t => array.Any(id => id == t.Id)).ToListAsync();

      You will get the error:

      Expression not supported: (id == t.Id) because the two arguments are serialized differently.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            mads.stahnke@f24.com Mads Stahnke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None