I'm trying to optimize DB size for a collection that contains a lot of documents. The documents have a number of properties that are represented by small integers (< 255). In the SQL Server world these would be stored as tinyint values, but the smallest BSON type I can find is Int32.
Are there an alternatives for efficiently storing small integers in MongoDB?
Integer: In MongoDB, the integer data type is used to store an integer value. We can store integer data type in two forms 32 -bit signed integer and 64 – bit signed integer.
Integer − This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server. Boolean − This type is used to store a boolean (true/ false) value. Double − This type is used to store floating point values.
MongoDB is a NoSQL Server in which data is stored in BSON (Binary JSON) documents and each document is essentially built on a key-value pair structure. As MongoDB easily stores schemaless data, make it appropriate for capturing data whose structure is not known.
Tinyint
data type is equal by Byte
(-256 < Byte < 255) and SmallInt
by Int16
.
But MongoDB stores data in a binary format called BSON which supports these numeric data types:
Reference:
Does MongoDB support floating point types?
BSON Types
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With