MongoDB Data type

Hello everyone, in this article we will learn about MongoDB data type in details. Let’s go. MongoDB Data Model

MongoDB with .Net Core course link => MongoDB

Datatypes in MongoDB

A MongoDB stores documents in BSON data format provides some different types used when storing the JavaScript objects in the binary form. BSON itself approaches from Binary encoded JSON. In MongoDB, all the BSON (BSON is a binary serialization format used store documents and create remote procedure calls in MongoDB) data types are supported such as date and binary that aren’t supported in JSON. When working with the different data types in MongoDB, it is the order in which they are compared when querying to find and update data.

Following are the different MongoDB data type that MongoDB supported each BSON type has both integer and string identifiers as listed and each BSON data type has an alias as well as a number which can be used for finding or searching the records:

Type Number Alias Notes
Double 1 “double”  
String 2 “string”  
Object 3 “object”  
Array 4 “array”  
Binary data 5 “binData”  
Undefined 6 “undefined” Deprecated.
ObjectId 7 “objectId”  
Boolean 8 “bool”  
Date 9 “date”  
Null 10 “null”  
Regular Expression 11 “regex”  
DBPointer 12 “dbPointer” Deprecated.
JavaScript 13 “javascript”  
Symbol 14 “symbol” Deprecated.
JavaScript (with scope) 15 “javascriptWithScope”  
32-bit integer 16 “int”  
Timestamp 17 “timestamp”  
64-bit integer 18 “long”  
Decimal128 19 “decimal” New in version 3.4.
Min key -1 “minKey”  
Max key 127 “maxKey”  

Above data from MongoDB website here is the Source link:

MongoDB with .Net Core course link =>


BSON double data type is used to store floating point values.


The string is used to store data and its most commonly used datatypes. In MongoDB String must be UTF-8 valid.


The BSON Object data type is used for embedded documents in MongoDB. If documents embedded in another document in the form of a Key value pair, then such type of document is known as an embedded document.


The BSON Array data types stores array in MongoDB. The array represents a set of values. The Array data types store multiples of values and data types such as Integer, Double, Date, String, etc.

Binary data

The BSON Binary data type is used to store the binary data in MongoDB.


The BSON Undefined data type is stores the undefined values in MongoDB.

MongoDB with .Net Core course link =>


The BSON ObjectID data type stores the document’s ID in MongoDB. ObjectID data types are fast to generate, small, likely unique and ordered. Its size is 12 bytes which are divided into four parts as follows:

Part Name Size (Bytes)
TimeStamp 4
Machine ID 3
Process Id 2
Counter 3


The BSON Boolean data type is stores the Boolean values that are true/false in MongoDB.


The BSON Date data type stores the current date or time in UNIX time format. In Date data type you can specify your own date time by creating an object of Date (Date objects are stored as a 64-bit integer representing the number of milliseconds) and passing a day, month and year into it. Following table we have discussed the methods for the date:

Date Methoe Description
Date() Date () returns the current date in string format.
New Date() New Date () returns a date object using the ISODate() wrapper.
ISODate() ISODate returns also a date object using ISODate() wrapper.


The BSON Null data type stores a null value in MongoDB.

Regular Expression

The BSON Regular Expression data type is store regular expression.


The BSON JavaScript data types store the JavaScript data without a scope.


The BSON Symbol data types used to store string but reserved for languages that use the specific symbol. The symbol data type is not supported by a shell, but if the shell gets a symbol from the database, the symbol data type is converted into strings.

JavaScript (with scope)

The BSON JavaScript data types store the JavaScript data with a scope.


The BSON Integer data type used to store an integer value or numeric value. Integer two forms available 32 bits and 64 bits and it depending upon the server.


The BSON Timestamp data types are used to store a timestamp and it is 64-bit value data type. Timestamp useful when modify our data to keep a record.

Min Key

Min Key compares the value of the lowest BSON element values.

Max key

Max Key compares the value of the highest BSON element values.

MongoDB with .Net Core course link =>

In this article, we have discussed the basic data types of MongoDB. BSON is supported time data type but JSON is not supported time data type.

sagar jaybhay

4 thoughts on “MongoDB Data type

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top