I have little experience with MongoDB. I am usual working on large scale SQL server DBs.
MongoDB only supports double and there is no decimal. The C# driver serializes decimals as strings.
What functionality do I miss if I store decimals as strings in MongoDB?
Is there a way to set a default serialization of decimals as double (AllowTruncation) without having to put an Attribute on each property?
What do I lose in precision if I used Bson double?
Thanks for your help!
UPDATE
I have an existing application model that uses decimals in C#. I want to use MongoDB as a new DB layer and change as little in the existing app as possible. Thats why I am looking for a way to map decimals in C# to double in MongoDB.
I understand that I loose precision and would have to analyze the side effects of it. My only remaining question is to know if there is a way to set a default serialization of decimals as double.
Thanks again. Great answers and comments so far.
As of Mongodb 3.4 and the 2.4 Mongodb C# driver, decimal types are supported.
The properties of your document must have the
[BsonRepresentation(BsonType.Decimal128)]
attribute found in theMongoDB.Bson.Serialization.Attributes
namespace.this will map to
"YourDecimalValue" : NumberDecimal("100.0000")
in MongodDB. Robomongo supports the new decimal type from version 1.1 Beta.I will answer your question partially (because I do not know much about C#).
So what will you lose if you will store decimals as strings.
What will you lose in precision if you store decimal as double:
.
Regarding the 2-nd subquestion:
I do not really understood it, so I hope someone would be able to answer it.