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.
- is related to
-
CSHARP-1891 Distinct should still work when TField is not exactly right (like it used to)
- Closed