MongoDB stores data in a format called Binary JSON (BSON) which extends JSON with additional data types. Here's a list of data types supported by MongoDB:
- String: Most common data type for storing text. BSON strings use UTF-8 encoding.
- Integer: Stores whole numbers. Can be 32-bit or 64-bit depending on your server configuration.
- Double: Stores floating-point numbers with 64-bit precision.
- Boolean: Represents true or false values.
- Array: Used to store an ordered list of values of any data type.
- Object: Represents complex data structures with key-value pairs. Can be nested within other documents.
- Date: Stores dates and times in Unix timestamp format (milliseconds since epoch).
- Timestamp: Used internally by MongoDB for operations involving timestamps.
- Null: Represents missing or absent values.
- Binary: Stores binary data like images or files. Limited to 16MB per document.
- ObjectId: A unique 12-byte identifier assigned to each document by MongoDB.
- Symbol: Similar to a string, but less commonly used. Reserved for specific languages.
- Code: Stores JavaScript code to be executed within MongoDB.