- The documents are stores in BSON, which is the binary encoded format of JSON in MongoDB.
- In MongoDB we can make remote procedure calls using BSON.
- BSON data format supports various data-types.
- There are various datatypes used in MongoDB.
Null :
- It is used to store Null values.
Syntax: {“x”: null}
Boolean :
- It is used to store whether true or false.
Syntax: {“x”: true}
Integer :
- It is used to store an integer value.
- In two forms we can store integer data type 32 -bit signed integer and 64 – bit signed integer.
Syntax: {“x”: 4}
String :
- It is used to store data and the most commonly used data type in MongoDB, BSON strings are of UTF-8.
- In each programming language, the drivers convert from the string format of the language to UTF-8 while serializing and deserializing BSON.
Syntax: {“x”: “foobar”}
Date :
- It is used to store date, and it is a 64-bit integer that represents the number of milliseconds.
- It is signed and the BSON data type generally supports UTC datetime.
- If the value of the date data type is negative, then it represents the dates before 1970.
- In this type, there are various type:
-
- Date ()
- New Date ()
- New ISO Date ()
Syntax: {“x”: “new Date ()”}
Regular expression :
- It is used to store regular expressions.
Syntax: {“x”: /foobar/i ()”}
Array :
- It is the set of values and stores the same or different data types values in it.
- The array is created using square brackets ([]) in MongoDB.
Syntax: {“x”: [“a”, “b”, “c”]}
Object ID :
- MongoDB automatically creates a unique object ID Whenever we create a new document in the collection.
- In MongoDB, there is an _id field for each document.
- The data stored in Id is length is 12 bytes and it is in hexadecimal format.
Syntax: {“x”: objectId ()}
Binary Data :
- It is used to store binary data. It is a string of arbitrary bytes.
Code :
- The string data type is similar to this data.
- Mongo shell is generally not supported in this.
- If the shell gets a symbol from the database, then it converts this type into a string type.
Syntax: {“x”: function() { /* …*/ }}