Datatypes in MongoDB

Welcome to a tutorial on Datatypes in MongoDB.

 

About Datatypes

As you may already know, MongoDB stores the JSON data in a binary encoded format called BSON, where the JSON data model actually extends the BSON to provide more flexibility with the additional data types and helps in easily encoding and decoding the data across different languages. However, by default, there is no support for the datatypes like date in JSON, but BSON provides that feature.

MongoDB supports the list of datatypes in the table. Every datatype in MongoDB possesses a unique number.

DatatypeNumberDescription
Double1It is used to store floating point values
String2It is a commonly used datatype and it is UTF-8 valid
Object3It is used for storing embedded objects
Array4It is used for storing embedded objects
Binary Data5It is used to store binary data
Undefined6It is used to store undefined value
Object Id7It is used to store a document's ID
Boolean9It is used to store a Boolean value
Date10It is used to store the current date time in UNIX format.
Null11It is used to store a null value
Regular Expression12It is used to store the regex
Javascript13It is used to store JavaScript data without scope
Symbol14Typically, it is used to store strings, but reserved for languages that use a specific symbol
Javascript with scope15It is used to store JavaScript data with a scope
Integer16 & 18It is used to store a numerical value
Timestamp10It is used to track when a document is modified.
Min/Max Key255/127It is used to compare a value against the lowest and highest BSON elements