[CSHARP-1975] Change of BsonNull.Value in c# driver from Version 2.2 to 2.4.3 Created: 02/May/17 Updated: 27/Oct/23 Resolved: 03/May/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON |
| Affects Version/s: | 2.4.3 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Blocker - P1 |
| Reporter: | Dheeraj kumar | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | Bug, question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Minor Change |
| Description |
|
I am using BsonValue.Null for querying in filter In Version 2.2 this query is rendered as , { "TransactionKey" : "" }] } but in Version 2.4.3 this query is rendered as , { "TransactionKey" : "" }] } So is the value of BsonValue.Null is changed from null to "BsonNull" purposely or is it a defect? |
| Comments |
| Comment by Githook User [ 17/May/17 ] | |||
|
Author: {u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}Message: | |||
| Comment by Robert Stam [ 03/May/17 ] | |||
|
This is a side effect of some improvements we have made to how constant values are serialized when building a query. We now attempt to convert the supplied constant value to the type of the field so that we can use the field's serializer to serialize the constant value. This is specially important when the field has a serializer that serializes values in a non-standard way. Here's an explanation of what's happening. When you write:
the compiler is inferring the type of <TField> from the supplied value. So that's actually equivalent to:
But... the actual field is of type string, not BsonNull. So we now convert the BsonNull constant to a string, and that's where the "BsonNull" string is coming from. The easy workaround is to use null instead of BsonNull as the value:
Note: you have to supply the <string> type parameter because the compiler can't infer a type from null. |