[CSHARP-2217] System.Decimal support in FilterDefinitionBuilder Created: 16/Mar/18  Updated: 27/Oct/23  Resolved: 16/Mar/18

Status: Closed
Project: C# Driver
Component/s: Operations
Affects Version/s: 2.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Denis Vlah Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Issue related to driver only


Issue Links:
Related
is related to CSHARP-2210 System.Decimal is serialized as a str... Closed

 Description   

When a filter is created with the FilterDefinitionBuilder for a decimal value then the resulting BsonDocument for the filter is constructed in the wrong way:

 var mongoClient = new MongoClient();
 var db = mongoClient.GetDatabase("db1");
 var collection = db.GetCollection<BsonDocument>("c1");
 decimal val = 99999421999.002M;
 var b =  new FilterDefinitionBuilder<BsonDocument>();
 var filter = b.Eq("f1", val);
 var bsonDocFiler = filter.Render(collection.DocumentSerializer, collection.Settings.SerializerRegistry);
 Console.WriteLine(bsonDocFiler["f1"].BsonType);



 Comments   
Comment by Robert Stam [ 16/Mar/18 ]

This is working as designed, for several reasons:

1. The C# driver has been serializing System.Decimal as string since before the BSON Decimal128 data type was introduced
2. System.Decimal and the BSON Decimal128 data type are not the same, they have different ranges and precisions

See CSHARP-2210 for more details.

Comment by Denis Vlah [ 16/Mar/18 ]

In the code snipped from issue description the string type is output to the console. But it should be the decimal.
As result when the filter is used in the real query nothing is returned.

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