[CSHARP-1594] Add support for Decimal128 BSON type Created: 07/Mar/16  Updated: 27/May/22  Resolved: 01/Sep/16

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 2.4

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-1393 Support decimal numbers Closed
is depended on by DRIVERS-288 Decimal 128 type support Closed
Epic Link: MongoDB 3.4
Server Compat: 3.3

 Description   

Add driver support for a new BSON type for decimal numbers, which will be added to MongoDB in version 3.4.

This type will use the decimal128 format as defined by the IEEE 754 standard and support up to 34 decimal digits and a range from -9.999999999999999999999999999999999×10^6144 to +9.999999999999999999999999999999999×10^6144. It also supports positive and negative zero, positive and negative infinity, and two forms of NaN (regular and signaled).

Decimal values will be treated like any other numeric type, and compare and sort correctly with other types based on actual numeric value. Operations on decimals are implemented in accordance with the standard, so a value of 0.10 will retain its trailing zeros while comparing equal to 0.1, 0.10000 etc.



 Comments   
Comment by Shawn Shaddock [ 03/Dec/16 ]

As George stated, I am also having the same experience. By default System.Decimal is still serializing to strings.

I tried to force them to serialize to Decimal128 using [BsonRepresentation(BsonType.Decimal128)] but then I get an error when performing an InsertOneAsync:
"MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream."

I am using:
C# Driver v2.4.0
MongoDB v3.4.0

Comment by George Jreige [ 25/Nov/16 ]

Hi All,

I am trying out the c# 2.4-beta2 driver and it seems it is still treating decimals as strings and sending a string value in the query to mongo.

I am using "MongoDB.Driver": "2.4.0-beta1" in my project.json and I have mongo server 3.4 running.

My filter def is:

filter = filter & builder.Gte(x => x.Price, info.PriceFrom)
& builder.Lte(x => x.Price, info.PriceTo);

info.PriceFrom and info.PriceTo are decimals and the documents in mongo are decimals not strings.

The output of the query to mongo is:

find({"Price" :

{ "$gte" : "0", "$lte" : "100000000" }

}).

Query works fine when I modify the query and run it in the Mongo shell as such: find({"Price" :

{ "$gte" : 0, "$lte" : 100000000 }

})

Am I missing something here? It very well could be me...

Regards,
George

Comment by Githook User [ 29/Sep/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1594: Add support for Decimal128 BSON type.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/ee97df791d0a42853295bcc5cd791e37b8bb076d

Comment by Githook User [ 24/Sep/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1594: Add support for Decimal128 BSON type.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/ee97df791d0a42853295bcc5cd791e37b8bb076d

Comment by Githook User [ 21/Sep/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1594: Add support for Decimal128 BSON type.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/277ed926ea18b9291abbe37f1c47f6e75b8e6e8c

Comment by Githook User [ 16/Sep/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1594: Add support for Decimal128 BSON type.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/a3683505975fd0bb7d1d6412446e923ee3023c99

Comment by Githook User [ 01/Sep/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1594: Add support for Decimal128 BSON type.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/dca002e73ba42c7f49869203d2533fc8318c3a43

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