Decimal Support for MongoDB
See original GitHub issueBefore General Availability, we had to remove Decimal
support because we depend on the MongoDB Rust Driver which doesn’t yet support MongoDB’s Decimal128. Here’s their JIRA ticket.
You can learn more details in this issue.
For now, we suggest using String
in place of Decimal
. Once the MongoDB Rust Driver supports Decimal128, we’ll re-introduce Decimal support for MongoDB in Prisma
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Model Monetary Data — MongoDB Manual
Using the Decimal BSON Type which is a decimal-based floating-point format capable of providing exact precision. Available in MongoDB version 3.4 and later....
Read more >MongoDB - What about Decimal type of value? - Stack Overflow
MongoDB 3.4 includes a new Decimal BSON type which provides exact precision for manipulating monetary data fields. Share.
Read more >Storing decimals values in MongoDB with C# - Developer ...
Prior MongoDB version 3.4 there was no Decimal BSON Type, if we wanted to store any numerical value where we needed exact precision...
Read more >Which one better `Double VS Decimal` in Mongo? - help
If you can have a fractional quantity of something, monetary prices should be specified using the mongo decimal format. theara May 23, 2019,...
Read more >Monetary Data Type Storage in MongoDB | Blog of Ken W. Alger
One of the features in version 3.4 of MongoDB is support for the NumberDecimal data type. This data type allows for 128-bit decimal...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We ended up building quite a complex middleware that converts back and forth between Float and Decimal. We couldn’t afford to change all arithmetics within the code base and once Mongodb releases the fix, we reconvert everything again to Decimal arithmetics.
Is there a solution to modify prisma’s data validator or maybe processor to convert Decimal objects to Float or String? We have built a new version of our app entirely on the
Decimal
object and the code uses it everywhere.We tried building middleware to convert
Decimal
toFloat
and keep a backup asString
in the metadata of the object (stored as Json) and vice versa, fromString
/Float
when retrieving toDecimal
. However, this works only on the model itself but won’t work properly for nested queries and will become very quickly unmanageable because of the amount of deep sub-queries you can do in relations.I was thinking to simply monkey patch Prisma so that whenever it finds a
Decimal
object, it simply converts it toFloat
orString
types during creation and vice versa, fromString
andFloat
toDecimal
based on the field name and model name during data fetch.