Joe Enzminger
Joe Enzminger

Reputation: 11190

Methods for storing small integers in 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?

Upvotes: 7

Views: 2837

Answers (1)

Behzad
Behzad

Reputation: 3580

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

Upvotes: 3

Related Questions