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

In should still work when TField is not exactly right (like it used to)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.2
    • Affects Version/s: 2.4.1
    • Component/s: API
    • None

      Take this little class

      public class Post
      {
          public String Id { get; set; }
          public String Title { get; set; }
          public String[] Tags { get; set; }
      }
      

      Notice that the TAGS property is an array of string.

      And now this query that runs perfectly fine with 2.4.0 version or earlier

      var result = _collection.Find(
          Builders<Post>.Filter.In("Tags", new[] { "Tag1" }))
          .ToList();
      

      I know that this query is not really correct, because it should use the AnyIn operator, but it runs fine with every version of 2.x driver up to 2.4.0, and also if you know Mongo javascript api you are perfectly fine issuing an $in query for a property that is an array of string.

      Now if you upgrade the driver to 2.4.1 the above query have an error.

      Test 'NewDriver.Query.InOnArray.verify_in_query' failed: System.InvalidCastException : Unable to cast object of type 'System.String' to type 'System.String[]'.
      	at MongoDB.Driver.FieldValueSerializerHelper.CastingSerializer`2.Serialize(BsonSerializationContext context, BsonSerializationArgs args, TFrom value)
      	at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Serialize[TValue](IBsonSerializer`1 serializer, BsonSerializationContext context, TValue value)
      	at MongoDB.Driver.SingleItemAsArrayOperatorFilterDefinition`2.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
      	at MongoDB.Driver.MongoCollectionImpl`1.CreateFindOperation[TProjection](FilterDefinition`1 filter, FindOptions`2 options)
      	at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
      	at MongoDB.Driver.FindFluent`2.ToCursor(CancellationToken cancellationToken)
      	at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
      	C:\Users\GianMariaRicci\Source\Repos\MongoDbNewDriverTest\NewDriver\Query\InOnArray.cs(56,0): at NewDriver.Query.InOnArray.verify_in_query()
      

      I know that the query should be really changed to AnyIn, but this is a breaking compatibility with version 2.4.0 and it requires at least a change in minor driver number.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            alkampfer@nablasoft.com Gian Maria Ricci
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: