What are MongoDB data types?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex MongoDB topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

MongoDB's BSON format supports more data types than JSON. String: UTF-8 encoded strings — most common type for text. Integer: Int32 (32-bit) and Int64 (64-bit) — numbers without decimal. Double: 64-bit floating-point — JSON "number" maps to this. Decimal128: high-precision 128-bit decimal for financial calculations (avoids floating-point errors). Use for money values. Boolean: true/false. Date: 64-bit integer representing milliseconds since Unix epoch. new Date() in mongo shell; ISODate("2024-01-15"). Always store dates as Date type, not strings. Timestamp: special BSON type for internal MongoDB use (not for application dates — use Date instead). ObjectId: 12-byte unique identifier, default _id type. Array: ordered list of values. Values can be any BSON type. Embedded document: nested document (object) as a value. Binary Data: byte arrays — for images, files (though large files should use GridFS or S3). Null: represents missing or undefined value. Regular Expression: stored as PCRE regex. JavaScript: JavaScript code (rare use). MinKey/MaxKey: special values that compare lower/higher than any other BSON value — used in shard key bounds. Symbol: deprecated. Type checking in queries: db.users.find({ age: { $type: "int" } }) or { $type: 16 } (BSON type number for Int32).

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a MongoDB codebase.