MongoDB data types
Documents in MongoDB are JSON-like objects. JSON is a simple representation of data. It supports the following data types:
null
: Thenull
data type is used to represent thenull
value as well as a value that does not exist:
![](https://static.packt-cdn.com/products/9781787288867/graphics/1dde31a2-e940-4259-a04d-1992370378ca.png)
boolean
: Theboolean
type is used to representtrue
andfalse
values:
![](https://static.packt-cdn.com/products/9781787288867/graphics/d2d11de3-d8e6-4062-952a-6fe9a480a098.png)
number
: In MongoDB, the shell default supports 64-bit floating-point numbers. To process long and integer numbers, MongoDB providesNumberLong
andNumberInt
, which represent 4 bytes and 8 bytes, respectively.string
: Thestring
data type represents the collection of characters. The MongoDB default supports UTF-* character encoding:
![](https://static.packt-cdn.com/products/9781787288867/graphics/4ee7a13d-5e0d-4e2b-9cf5-a4f7c46d77db.png)
date
: MongoDB stores dates in milliseconds since the epoch. The time zone information is not saved:
![](https://static.packt-cdn.com/products/9781787288867/graphics/76c73626-7b9f-4b72-9bfc-aa60fe5a3d2e.png)
- After inserting a date using the preceding way in the document, when we query using
find
it returns a document with a date in the following format:
![](https://static.packt-cdn.com/products/9781787288867/graphics/bee68689-d578-4173-a7b9-7e705ac6687a.png)
array
: A set or list of values represents arrays. Also, multiple JSON objects represent an array of elements. The...