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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 3.7.0
    • Affects Version/s: 3.2.0, 3.2.1
    • Component/s: LINQ
    • None
    • None
    • Fully Compatible
    • Dotnet Drivers
    • Not Needed
    • 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 Stam (Inactive)
            Reporter:
            Mads Stahnke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: