MongoDB Fundamentals
MongoDB Data Types
The types you will actually query: strings, numbers, dates, arrays, embedded documents, Decimal128.
You already know BSON adds types. These are the ones you will query in a backend. One document, several types — that is more useful than a catalogue.
{
_id: ObjectId("64a1b2c3d4e5f6a7b8c90021"),
name: "Mechanical Keyboard", // String
price: NumberDecimal("4500.00"), // Decimal128 — money
stock: 20, // Int32
rating: 4.6, // Double
inStock: true, // Boolean
tags: ["electronics", "peripherals"], // Array of strings
specs: { switches: "brown", wireless: false }, // Embedded document
releasedAt: ISODate("2026-01-15"), // Date
discontinuedAt: null // Null
}- String, Boolean, Array, embedded document, ObjectId, Null — everyday. Arrays and nested objects are why documents are not just rows.
- Integer vs Double —
20is an integer;4.6is a float. Mixing them on the same field (stock: 20on one doc,stock: 20.0on another) makes equality queries miss. Be consistent. - Date —
ISODate/ JavaScriptDate. Not a string. Range queries and sorts then mean what you think. - Decimal128 —
NumberDecimal("4500.00")in the shell;Decimal128in Node.js. Use it for money. A Double cannot represent0.1exactly; ledgers notice. Integers in the smallest currency unit (paise, cents) are also fine if the whole team agrees.
Orders in these lessons use amount: 4500 as an integer of rupees. That is a valid choice. What you must not do is store 4500.50 as a binary floating-point Double and then sum it across a million rows.
Interview question
Which MongoDB types do you actually use, and how would you store money?
Strings, booleans, dates, arrays, nested documents, ObjectId. Numbers as integers or doubles depending on the field. Money as Decimal128 or as integer minor units — not as a Double.
Practice
Booleans are just fields. Match them like anything else.