question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decimal Support for MongoDB

See original GitHub issue

Before 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:open
  • Created a year ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aladinfluxcommented, May 21, 2022

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.

1reaction
aladinfluxcommented, Apr 9, 2022

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 to Float and keep a backup as String in the metadata of the object (stored as Json) and vice versa, from String/Float when retrieving to Decimal. 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 to Float or String types during creation and vice versa, from String and Float to Decimal based on the field name and model name during data fetch.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found