Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Methods for storing small integers in MongoDB

Tags:

mongodb

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?

like image 469
Joe Enzminger Avatar asked Jun 04 '15 00:06

Joe Enzminger


People also ask

How number is stored 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.

What are different data types available in MongoDB?

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.

Which of these types of data in can be stored in a MongoDB collection *?

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.


1 Answers

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:

  • int32 - 4 bytes (32-bit signed integer)
  • int64 - 8 bytes (64-bit signed integer)
  • double - 8 bytes (64-bit IEEE 754 floating point)

Reference:

Does MongoDB support floating point types?

BSON Types

like image 165
Behzad Avatar answered Sep 28 '22 04:09

Behzad