[CSHARP-1456] Regex Created: 25/Oct/15  Updated: 06/Nov/15  Resolved: 02/Nov/15

Status: Closed
Project: C# Driver
Component/s: BSON, Documentation, Serialization
Affects Version/s: 2.1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Amilcar Calles Assignee: Craig Wilson
Resolution: Won't Fix Votes: 0
Labels: BsonRegularExpression, Regex
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10, Visual Studio 2015


Backwards Compatibility: Minor Change

 Description   

This is just to notify a breaking change, the regex find query has to change from .Eq to .Regex in order to work,

In Driver 2.0.1 this works:

var filter = new FilterDefinitionBuilder<MyModel>()
                    .Eq(
                        x => x.MyStringField,
                        new BsonRegularExpression("^mongo", "i")
                    );

In Driver 2.1.0 the above example throws a Casting exception between String and Regex,

Unable to cast object of type 'MongoDB.Bson.Serialization.Serializers.StringSerializer' to type 'MongoDB.Bson.Serialization.IBsonSerializer`1[MongoDB.Bson.BsonRegularExpression]'

so I need to change to this:

var filter = new FilterDefinitionBuilder<MyModel>()
                    .Regex(
                        x => x.MyStringField,
                        new BsonRegularExpression("^mongo", "i")
                    );



 Comments   
Comment by Amilcar Calles [ 06/Nov/15 ]

You're right, I even think that this new way to match regex is even cleaner, the main reason of this post is to let you know that, for us developers that were working on 2.0.1 and upgrade it to 2.1 was kind of headache because there was not a clear reason in the debuger for the error, neither was documentation about this breaking change (even the documentation said that there was no breaking changes), so in my case I literaly used the Visual Studio IntelliSense to discover what should I use instead of the old ".Eq".

Comment by Craig Wilson [ 02/Nov/15 ]

Hi Amilcar,

Thanks for the report. I apologize this happened. It was inadvertant. However, we have decided that we will not be fixing this. Some changes of how serialization work would make it non-trivial. Also, given that the Regex method already exists, there is a good workaround already.

Craig

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