Skip to content

MongoDB Fundamentals

MongoDB Data Types

The types you will actually query: strings, numbers, dates, arrays, embedded documents, Decimal128.

BeginnerAbout 5 minutes

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
}
A product plus a nested inventory object and a review-friendly array
  • String, Boolean, Array, embedded document, ObjectId, Null — everyday. Arrays and nested objects are why documents are not just rows.
  • Integer vs Double20 is an integer; 4.6 is a float. Mixing them on the same field (stock: 20 on one doc, stock: 20.0 on another) makes equality queries miss. Be consistent.
  • DateISODate / JavaScript Date. Not a string. Range queries and sorts then mean what you think.
  • Decimal128NumberDecimal("4500.00") in the shell; Decimal128 in Node.js. Use it for money. A Double cannot represent 0.1 exactly; 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?

Think about it first.

Practice

Booleans are just fields. Match them like anything else.