Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

data-types-mongodb

MongoDB data types

Last reviewed Jun 1, 2026 Content v20260601
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
beginner

This lesson

This lesson teaches MongoDB data types: document modeling, query operators, and aggregation patterns for MongoDB.

Teams query MongoDB data types on every MongoDB codebase—skipping it leaves gaps in debugging and data reviews.

You will apply MongoDB data types in contexts like: Content catalogs, event logs, mobile sync backends, and polyglot stacks beside SQL services.

Copy JavaScript shell queries from each lesson into mongosh or MongoDB Atlas Data Explorer—inspect matched documents and explain plans. The in-browser lab (execution_profile: none) ships later; mongosh is the practice path now.

When you can explain the previous lesson's ideas without copying example queries verbatim.

BSON adds types beyond JSON: ObjectId, Date, Decimal128, BinData, and more. Pick types for query and index behavior.

Common types

  • String, Boolean, Int32/Int64, Double — scalars
  • Date — UTC instant (ISODate in shell)
  • ObjectId — default _id, 12-byte identifier
  • Decimal128 — exact decimals (money)
  • Null — explicit null vs missing field

Typed insert

db.ledger.insertOne({
  amount: NumberDecimal('19.99'),
  postedAt: ISODate('2026-01-15T12:00:00Z')
})

Practice: Run in mongosh on your practice database.

Missing vs null

A missing field and null behave differently in queries—design APIs consistently.

Important interview questions and answers

  1. Q: Money as double?
    A: Avoid float rounding—use Decimal128 or integer cents.
  2. Q: ObjectId contains timestamp?
    A: First 4 bytes encode creation time—rough ordering possible.

Self-check

  1. Which type for currency?
  2. Difference between missing field and null?

Tip: Use Decimal128 or integer cents for money—avoid binary float surprises.

Interview prep

Money type?
Decimal128 or integer cents—avoid float.
Null vs missing?
Different query semantics—be consistent in APIs.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Decimal128 when?
  • Null vs missing?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump