LearnThatStack Ace your next interview
Database Technologies

MongoDB.

Start free Change topic Change
Practice · Questions

All questions

Showing of 57
Beginner 10
01

What is MongoDB and what are its key features?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

MongoDB is a document-oriented NoSQL database. It stores each record as a flexible, JSON-like document in BSON, short for Binary JSON. Documents live in collections instead of tables.

Its key features are:

  • A flexible schema, so documents in one collection can have different structures.
  • A rich query language with complex queries, indexes and an aggregation pipeline.
  • High availability through replica sets, which keep copies of the data and fail over automatically.
  • Horizontal scaling through built-in sharding, which spreads data across many servers.
  • GridFS for storing large files.
  • Multi-document ACID transactions, which make several writes succeed or fail together.
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

Explain the difference between SQL and NoSQL databases. Why choose MongoDB?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

SQL databases store data in tables with a fixed schema and join tables at query time. NoSQL databases such as MongoDB drop the fixed schema and store data in other shapes, like documents, so related data can live together.

SQL databases MongoDB
Data model Tables of rows and columns Collections of JSON-like documents
Schema Fixed and defined in advance Flexible, so documents can differ
Relationships Joins across tables Embedded data, or $lookup when needed
Scaling Mostly vertical, on a larger server Horizontal, through sharding, which splits data across many servers
Transactions ACID transactions are standard Single-document writes are atomic, and multi-document ACID transactions are available

Choose MongoDB when the data is semi-structured or changes shape often, and when documents match the objects in your code. That match speeds up development, which suits fast-moving projects such as modern web applications. MongoDB also suits applications that must scale horizontally.

A relational database stays the better fit when most queries join many tables. SQL databases also have a mature ecosystem of tools.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is BSON and how does it differ from JSON?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

BSON, short for Binary JSON, is the binary format MongoDB uses to store documents and to send them over the network. It looks like JSON when you read it in the shell, but it is encoded as bytes and supports more types.

How it differs from JSON:

  • JSON is text, while BSON is binary.
  • BSON adds types that JSON lacks, such as ObjectId, Date and binary data.
  • BSON is faster to parse and easier to traverse.
  • BSON can take more space than the same JSON, because it stores extra metadata.

These values use BSON types that plain JSON cannot express.

{
  _id: ObjectId("507f1f77bcf86cd799439011"),
  created: ISODate("2023-01-01T12:00:00Z"),
  data: BinData(0, "SGVsbG8gV29ybGQ=")
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

Explain MongoDB's data hierarchy: Database, Collection, Document.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

MongoDB organizes data in three levels: a database holds collections, and a collection holds documents.

  • A database is the top-level container for collections. MongoDB comes with the admin, local and config databases. By default, all databases keep their files in one data directory, and the directoryPerDB setting gives each database its own directory.
  • A collection is a group of documents, like a table in a relational database. Its documents can have different schemas. MongoDB creates a collection when you insert its first document.
  • A document is one record, a JSON-like structure stored as BSON, a binary form of JSON. It can hold nested documents and arrays, and it can be at most 16MB.

The diagram below shows an example structure.

Database: ecommerce
├── Collection: users
│   ├── Document: {_id: 1, name: "John", email: "john@email.com"}
│   └── Document: {_id: 2, name: "Jane", age: 25, city: "NYC"}
└── Collection: products
    └── Document: {_id: 1, title: "Laptop", price: 999.99}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What is ObjectId in MongoDB?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

An ObjectId is a 12-byte value that MongoDB uses as the default _id of a document. If you insert a document without an _id, one is generated for you.

It is written as 24 hex characters and has three parts.

  • 4 bytes: a timestamp in seconds since the Unix epoch, which is January 1, 1970.
  • 5 bytes: a random value generated once per process.
  • 3 bytes: a counter that starts at a random value and increments.

Because the timestamp comes first, ObjectIds sort by creation time to the second, and getTimestamp() returns that time. They are likely unique across machines, but uniqueness is not guaranteed.

// ObjectId example
ObjectId("507f1f77bcf86cd799439011")

// Extract timestamp
ObjectId("507f1f77bcf86cd799439011").getTimestamp()
// Returns: ISODate("2012-10-17T21:13:27Z")
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

Explain the basic CRUD operations in MongoDB.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

CRUD operations in MongoDB are the collection methods that create, read, update and delete documents. Each one has a form for one document and a form for many.

To create documents, insertOne() adds one document, and insertMany() takes an array and inserts each document in it. MongoDB adds an _id to any document that has none.

db.users.insertOne({name: "John", age: 30})
db.users.insertMany([
  {name: "Alice", age: 25},
  {name: "Bob", age: 35}
])

To read, find() returns a cursor over the matching documents, and with no filter it matches every document. findOne() returns the first match or null. A filter such as {age: {$gte: 25}} uses query operators.

db.users.find()
db.users.find({age: {$gte: 25}})
db.users.findOne({name: "John"})

To update, updateOne() changes the first match and updateMany() changes every match. Each takes a filter and an update document, and update operators such as $set change only the fields they name.

db.users.updateOne(
  {name: "John"}, 
  {$set: {age: 31}}
)
db.users.updateMany(
  {age: {$lt: 30}}, 
  {$set: {status: "young"}}
)

To delete, deleteOne() removes the first match and deleteMany() removes every match.

db.users.deleteOne({name: "John"})
db.users.deleteMany({age: {$lt: 18}})
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

Explain the difference between find() and findOne() methods.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

find() returns a cursor over every matching document, while findOne() returns the first matching document itself, or null when nothing matches.

  • A cursor is lazy. Documents load in batches as you iterate, so find() can walk a large result without holding it all in memory.
  • You can chain cursor methods onto find(), such as sort(), limit() and skip().
  • findOne() runs at once and returns a plain document, so it has no cursor methods to chain.
  • When several documents match, findOne() returns the first one it reaches. With a collection scan, that is the first in natural order, the order MongoDB stored them in. With an index scan, it is the first entry in the index.

Use findOne() to fetch one document by a unique field, and find() to read a list.

// find() - returns cursor
const cursor = db.users.find({age: {$gte: 25}})
cursor.forEach(doc => print(doc.name))

// findOne() - returns document
const user = db.users.findOne({email: "john@email.com"})
if (user) {
  print(user.name)
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What are MongoDB query operators? Provide examples.

Part of Pro
09

How do you perform updates in MongoDB? Explain update operators.

Part of Pro
10

What are indexes in MongoDB and why are they important?

Part of Pro
Intermediate 38
11

What is upsert in MongoDB?

Part of Pro
12

Explain the difference between single field and compound indexes.

Part of Pro Visual
13

What are sparse and partial indexes?

Part of Pro
14

How do you analyze query performance using explain()?

Part of Pro
15

What is a multikey index?

Part of Pro Visual
16

What is MongoDB's Aggregation Framework?

Part of Pro
17

How do you perform joins in MongoDB using $lookup?

Part of Pro Visual
18

What are aggregation operators in MongoDB, and how do you use them?

Part of Pro
19

Explain the $group stage and its accumulator operators.

Part of Pro Visual
20

What are the principles of schema design in MongoDB?

Part of Pro
21

When should you embed vs reference documents?

Part of Pro
22

How do you handle one-to-many relationships in MongoDB?

Part of Pro
23

How do you identify slow queries in MongoDB?

Part of Pro
24

What is the working set and why is it important?

Part of Pro
25

Explain MongoDB's storage engines.

Part of Pro
26

How does MongoDB handle memory management?

Part of Pro
27

What is replication in MongoDB and how does it work?

Part of Pro
28

Explain the concept of oplog in MongoDB.

Part of Pro
29

What happens during replica set elections?

Part of Pro
30

How do you configure read preferences in MongoDB?

Part of Pro
31

How do you implement authentication in MongoDB?

Part of Pro
32

Explain MongoDB's role-based access control (RBAC).

Part of Pro
33

Does MongoDB support ACID transactions?

Part of Pro
34

How do you backup and restore MongoDB databases?

Part of Pro
35

How do you monitor MongoDB performance?

Part of Pro
36

Explain MongoDB log analysis and troubleshooting.

Part of Pro
37

What is GridFS in MongoDB, and when would you use it?

Part of Pro
38

What are Text Indexes and how do you implement text search?

Part of Pro
39

What are Capped Collections and their use cases?

Part of Pro
40

What are write concern and read concern in MongoDB?

Part of Pro
41

What is the ESR rule for compound indexes in MongoDB?

Part of Pro
42

What are TTL indexes in MongoDB, and how do they work?

Part of Pro
43

What is a covered query in MongoDB?

Part of Pro Visual
44

What is a wildcard index, and when should you use one?

Part of Pro
45

What are some common MongoDB schema design patterns?

Part of Pro
46

What is schema validation in MongoDB, and how do you use it?

Part of Pro
47

What is sharding in MongoDB and when should you use it?

Part of Pro
48

How do you implement geospatial queries in MongoDB?

Part of Pro
Expert 9
49

How do you design schema for time-series data?

Part of Pro Visual
50

What are the best practices for MongoDB performance optimization?

Part of Pro
51

How do you choose a good shard key?

Part of Pro
52

Explain the role of config servers in sharding.

Part of Pro
53

What is chunk migration and how does the balancer work?

Part of Pro
54

How do you secure MongoDB in production?

Part of Pro
55

How do you implement multi-document transactions?

Part of Pro
56

What are the performance considerations for transactions?

Part of Pro
57

Explain MongoDB Change Streams.

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for MongoDB? Send them this set.
Pro · $10/mo

50 of 57 MongoDB answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git