MongoDB Data Types

One of the important reason why NoSQL database is preferred over RDMS is the extended number of data types that NoSQL Database have.

Therefore, some of the Data Types that MongoDB works on, are as follows:

1) String

The string is the most common type of Data Type MongoDB stores. In lamen terms, String can be considered as nothing but a normal text enclosed with ' ' or " ". Also, the BSON strings must be in UTF-8.

2) Boolean

Boolean values are those that are considered in terms of True and False.

3) Numbers

These Data Types are used to store numeric types of data. In MongoDB Numbers data types can be classified as:

  • integer(int 32)- Use to store an integer values 32 bits.
  • NumberLong(int 64)- use to store a value that is of 64 bits.
  • NumberDecimal(12.99)- This is used to store high precision float values.

4) ObjectId

Object Id is the unique id that is provided to every document in MongoDB. The _Id is used to uniquely identify MongoDB documents and is stored in hexadecimal format.

5) ISODate

The new ISODate() data type is used to return date format in ISODate() wrapper.

6) Timestamp

This new Timestamp() returns values as a current timestamp in milliseconds and is used to follow 64- bit format.

7) Object

Objects here, are the embedded document stored inside a collection in MongoDB. An embedded document means a nested document or a document inside another document.

8) Arrays

The array data type is used to store a list of values of a different data type enclosed in square brackets [].

9) Double

This is used to store low precision float values.

10) NULL

The NULL data type is used to store NULL values in MongoDB.