MongoDB Data Types

The BSON data format provides several different types that are used when storing the JavaScript objects to binary form. These types match the JavaScript types as closely as possible. It is important to understand these types because you can actually query MongoDB to find objects that have a specific property which has a value of a certain type. For example, you can look for documents in a database whose timestamp value is a String object or query for ones whose timestamp value is a Date object.

MongoDB assigns each of the data types an integer ID number from 1 to 255 that is used when querying by type. Table 11.1 shows a list of the data types that MongoDB supports, along with the numbers MongoDB uses to identify them.

Another thing you need to be aware of when working with the different data types in MongoDB is the order in which they are compared. When comparing values of different BSON types, MongoDB uses the following comparison order, from lowest to highest:

1. Min Key (internal type)

2. Null

3. Numbers (32-bit integer, 64-bit integer, Double)

4. Symbol, String

5. Object

6. Array

7. Binary Data

8. Object ID

9. Boolean

10. Date, Timestamp

11. Regular Expression

12. Max Key (internal type)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.137.10