MongoDB is noted for its tremendous scalability, availability, and performance. MongoDB's data types allow us to store data more efficiently while simultaneously performing very efficient and robust queries. The following are some of the most often used data types in MongoDB.

Become a Data Scientist with Hands-on Training!

Data Scientist Master’s ProgramExplore Program
Become a Data Scientist with Hands-on Training!

1. String

One of the most basic and widely used data types is the string. To represent text, the string type is utilized. Because BSON strings are UTF-8, we can easily express most international characters in them.

Example:

{

"intern_name":  "Edward Bill",

"intern_skills":  "Software Development",

"intern_salary":  7500,

"intern_status":  true,

}

2. Integer

Numeric values are stored using the integer data type. Depending on the server, it can store 32-bit or 64-bit numbers.

Example:

{

"intern_name":  "Edward Bill",

"intern_skills":  "Software Development",

"intern_salary":  7500,

"intern_status":  true,

}

Intern_salary is of the type integer since it stores a numeric number.

3. Double

Numeric numbers containing 8 bytes (64-bit IEEE 754 floating point) floating-point are stored using the double data type.

An example of a document with a double value in the field intern score is shown below.

{

"intern_name":  "Edward Bill",

"intern_skills":  "Software Development",

"intern_score":  87.75,

"intern_status":  true,

}

4. Boolean

Boolean (true or false) values are stored with the boolean data type. The field intern status is of the type boolean in the example below because it stores the value true. Booleans take up less space than integers or strings and avoid unwanted comparison side effects.

{

"intern_name":  "Edward Bill",

"intern_skills":  " Software Development",

"intern_score":  87.75,

"intern_status":  true,

}

5. Array

The array is stored using the array data type. We can store several values in a single key of the document with an array data type.

{

" intern_name":  "Edward Bill",

" intern_skills":  ["Software Development", "C++", "Java"],

" intern_score":  87.75,

" intern_status":  true,

}

Become a Data Scientist with Hands-on Training!

Data Scientist Master’s ProgramExplore Program
Become a Data Scientist with Hands-on Training!

6. Object 

An embedded document is a key-value pair that is put inside another document. Embedded documents are stored using the object data type. 

{

"product_code": "0000-XYZ",

"product_price": 39.99,

"product_dimensions": {

"product _height": 1000,

"product_width": 90,

"product_depth": 600,

},

"product_availability": true,

}

Because it has its own set of key-value pairs, the product dimensions field in the example above is an embedded document. As a result, this field is an Object field.

7. Date 

The current date or time is stored in the ‘Date’ data type. The returning date can be done in a variety of ways; either a string or a date object. There are three strategies that can be used in this situation. 

  1. The Date() function returns a string. 
  2. Return a date object with New Date().
  3. ISODate() returns a date object as well.

Example:

{

"employee_name": "John Doe",

"employee_dob": ISODate("2004-04-10T12:45:42.389Z"),

"employee_marks": 80.40

}

8. Timestamp 

The term "Timestamp" refers to a set of characters used to describe the date and time of an occurrence. The timestamp data type is commonly used to track the creation, editing, and updating of documents. Such characters are stored in the timestamp data type. To construct a timestamp, use the new Timestamp().

Example: 

{

"product_code": "0000-XYZ",

"product_price": 39.99,

"product_created": Timestamp(1531456567, 1),

"product_availability": true,

}

9. Null

The NULL data type is used to represent a value of zero or no value, as the name implies.

When a null value field in a document is queried, this is what it looks like:

{

"product_code": "0000-XYZ",

"product_price": 39.99,

"product_color": null,

"product_availability": true,

}

Become a Data Scientist with Hands-on Training!

Data Scientist Master’s ProgramExplore Program
Become a Data Scientist with Hands-on Training!

10. Binary

This data type is used in fields to hold binary data. In a relational database management system, this data type corresponds to the Blob type. Nonetheless, on the grounds that MongoDB has a report size limitation of 16MB, binary data can be implanted inside a document utilizing the Binary data type in the event that the full size of the binary data in addition to different fields is under 16MB.

{

"_id": "4567rttyygjuhutfv7890",

"product_code": "1234-ABCD",

"product_price": 49.99,

"product_availability": true,

"product_picture":BinData(1, "rk56tyvbu5677ghugf456..."),

}

Scale Your Data Science Career

To gain better knowledge about such intricate data science topics, consider pursuing a Professional Certificate Program in Data Science offered by Simplilearn. This program will assist you in fully comprehending the data science field. Professionals pursuing this course will be prepared for any challenges that may arise, as well as how to address them effectively using advanced data-driven decisions. Explore and enroll now!

Our Big Data Courses Duration And Fees

Big Data Courses typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Post Graduate Program in Data Engineering

Cohort Starts: 25 Apr, 2024

8 Months$ 3,850