TL;DR
STRING
if you want to make the arithmetic operations on the client.
BSON
if you want the arithmetic to happen within the db server and receive it in the response.
In depth (not that much)
It depends on where do you wish to place your numeric operations. You can always save the pricing as a String
type on MongoDB, always that you don't need to make server-side arithmetic (Non-Numeric Model) AND the precision on the decimals you need.
If you wish to make arithmetic operations from the query itself, you should use Bson
. Leaving you the official mongo related doc below:
Numeric Model
The numeric model may be appropriate if you need to query the database for exact, mathematically valid matches or need to perform server-side arithmetic, e.g., $inc, $mul, and aggregation framework arithmetic.
The following approaches follow the numeric model:
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.
Using a Scale Factor to convert the monetary value to a 64-bit integer (long BSON type) by multiplying by a power of 10 scale factor.
Non-Numeric Model
If there is no need to perform server-side arithmetic on monetary data or if server-side approximations are sufficient, modeling monetary data using the non-numeric model may be suitable.
The following approach follows the non-numeric model:
Using two fields for the monetary value: One field stores the exact monetary value as a non-numeric string and another field stores a binary-based floating-point (double BSON type) approximation of the value.
EDIT: Source: https://docs.mongodb.com/manual/tutorial/model-monetary-data/