Tsallaka zuwa abun ciki
Justice Tech School

MongoDB Exercises

Fill in the blanks to check your knowledge. Each exercise belongs to a lesson.

MongoDB Introduction

Exercise

Data is stored as ___.

Data is stored as 

MongoDB Get Started

Exercise

Open the shell.

 "mongodb://localhost:27017"

Databases, Collections and Documents

Exercise

Switch database.

 school

BSON Data Types

Exercise

Date type.

new ("2024-01-15")

ObjectId and _id

Exercise

Unique key field.

The field 

Atlas, Compass and Drivers

Exercise

GUI client.

MongoDB 

Insert One Document

Exercise

Add one document.

db.students.({ name: "Ada" })

Insert Many Documents

Exercise

Add several documents.

db.students.insert([...])

Find Documents

Exercise

Find with a filter.

db.students.find({ city:  })

Projection

Exercise

Hide _id.

{ _id:  }

Sort, Limit and Skip

Exercise

Newest first.

.sort({ age:  })

Counting Documents

Exercise

Count matches.

db.students.Documents({})

Cursors and Batches

Exercise

Convert to an array.

cursor.()

Comparison Operators

Exercise

Greater than.

{ age: { $: 18 } }

Logical Operators

Exercise

Either condition.

{ $: [ {a:1}, {b:2} ] }

Element and Type Operators

Exercise

Missing field.

{ phone: { $: false } }

Text Matching with Regex

Exercise

Names starting with A.

{ name: /a/ }

Querying Arrays

Exercise

Array length.

{ tags: { $: 3 } }

Querying Nested Documents

Exercise

Reach into address.

{ "address.": "Lagos" }

$expr and Computed Queries

Exercise

Compare two fields.

{ $: { $gt: [...] } }

Update Documents

Exercise

Change a field.

{ $: { city: "Abuja" } }

More Update Operators

Exercise

Add 5.

{ $: { points: 5 } }

Updating Arrays

Exercise

Add without duplicates.

{ $: { tags: "db" } }

Upsert and Replace

Exercise

Insert if missing.

{ : true }

findOneAndUpdate

Exercise

Return the new version.

returnDocument: ""

Delete Documents

Exercise

Delete all matches.

db.students.Many({ active: false })

Bulk Writes

Exercise

Many operations at once.

db.items.Write([...])

Embedding versus Referencing

Exercise

Reference field.

authorId points to the  _id

One to Many Patterns

Exercise

Parent reference.

{ Id: 1 }

Schema Validation

Exercise

Required fields list.

required: []

Indexes

Exercise

Unique index.

{ : true }

Explain Plans

Exercise

Show the plan.

.("executionStats")

Text and TTL Indexes

Exercise

Expire after an hour.

expireAfter: 3600

Embedding Documents

Exercise

Dot path.

"address."

Referencing Documents

Exercise

Link by id.

author_id points to 

One to Many Modeling

Exercise

Array of items.

reviews: []

Schema Design Rules

Exercise

Store together.

Data used together is  together

Schema Validation

Exercise

Validator key.

{ : {} }

Capped Collections

Exercise

Fixed size.

{ : true }

TTL Indexes

Exercise

Expire.

{ expireAfter: 60 }

Working with Dates

Exercise

New date.

new ("2026-03-15")

Aggregation Pipeline

Exercise

Group stage.

{ $: { _id: "$customer" } }

$match, $project and $addFields

Exercise

Computed field.

{ $: { tax: 5 } }

$group Accumulators

Exercise

Average.

{ $: "$amount" }

$unwind

Exercise

Split array elements.

{ $: "$tags" }

$lookup: Joins

Exercise

Join stage.

{ $: { from: "customers" } }

$facet, $bucket and $count

Exercise

Ranges.

{ $: { groupBy: "$price" } }

$out and $merge

Exercise

Save results.

{ $: { into: "daily" } }

Transactions

Premium exercise. See plans

Replica Sets

Premium exercise. See plans

Sharding

Premium exercise. See plans

Read and Write Concern

Premium exercise. See plans

Change Streams

Premium exercise. See plans

Atlas Search and Vector Search

Premium exercise. See plans

Time Series Collections

Premium exercise. See plans

GridFS and Large Files

Premium exercise. See plans

Security Checklist

Premium exercise. See plans

Backup and Restore

Premium exercise. See plans

Import and Export Data

Premium exercise. See plans

MongoDB with Node.js and Mongoose

Premium exercise. See plans

MongoDB with Python

Premium exercise. See plans

Monitoring and Performance

Premium exercise. See plans

Schema Design Patterns

Premium exercise. See plans

Migrating from SQL

Premium exercise. See plans

MongoDB Best Practices

Premium exercise. See plans

Next Steps

Premium exercise. See plans

What is MongoDB

Exercise

Stored as.

MongoDB stores 

Databases, Collections, Documents

Exercise

Switch database.

 shop

Using mongosh

Exercise

Open the shell.

BSON Types

Exercise

Date type.

new ()

ObjectId

Exercise

Default id field.

The  field is unique

insertOne

Exercise

Add one.

db.users.({ n: 1 })

insertMany

Exercise

Add many.

db.users.([])

find

Exercise

Read one.

db.users.({})

Projection

Exercise

Include a field.

{ name:  }

Comparison Operators

Exercise

Greater than.

{ age: { : 25 } }

Logical Operators

Exercise

Either condition.

{ : [a, b] }

$exists and $type

Exercise

Field present.

{ $: true }

Regular Expressions

Exercise

Regex operator.

{ name: { : "^A" } }

sort, limit and skip

Exercise

Descending.

sort({ age:  })

Counting

Exercise

Count with filter.

db.users.({})

distinct

Exercise

Unique values.

db.users.("country")

updateOne and $set

Exercise

Set a field.

{ : { age: 31 } }

updateMany

Exercise

Many.

db.users.(f, u)

$inc and $mul

Exercise

Add to a number.

{ : { qty: 1 } }

$unset and $rename

Exercise

Remove a field.

{ : { temp: "" } }

Array Updates

Exercise

Add once.

{ : { skills: "x" } }

Positional Update

Exercise

Matched item.

"items..qty"

Upsert

Exercise

Upsert option.

{ : true }

replaceOne

Exercise

Replace.

db.users.(f, d)

findOneAndUpdate

Exercise

Return new doc.

returnDocument: ""

Deleting Documents

Exercise

Delete many.

db.users.({})

Dropping Collections

Exercise

Drop.

db.temp.()

Creating Indexes

Exercise

Create.

db.users.({ e: 1 })

Unique Indexes

Exercise

Unique option.

{ : true }

Compound Indexes

Exercise

Two fields.

createIndex({ a: 1, : -1 })

explain

Exercise

Explain.

.("executionStats")

Text Search

Exercise

Text query.

{ : { $search: "x" } }

Aggregation Pipeline

Exercise

Filter stage.

{ : { status: "paid" } }

$group

Exercise

Count each.

n: { : 1 }

$project and $addFields

Exercise

Add a field.

{ : { x: 1 } }

$lookup

Exercise

Join.

{ : { from: "users" } }

$unwind

Exercise

Flatten.

{ : "$tags" }

$sort, $limit, $skip

Exercise

Top results.

{ : 5 }

$count and $facet

Exercise

Count stage.

{ : "n" }

Using the Node Driver

Exercise

Connect.

await client.()

Mongoose Basics

Exercise

Model builder.

mongoose.("User", schema)

Connection Strings

Exercise

Atlas scheme.

mongodb+://host

MongoDB Atlas

Exercise

Hosted service.

Atlas is  MongoDB

Users and Roles

Exercise

Role name.

role: ""

Backup and Restore

Exercise

Dump.

 --db shop

Import and Export

Exercise

Import.

 --db shop

Transactions Intro

Exercise

Session.

client.start()

Replica Sets

Exercise

Status.

rs.()

Sharding Intro

Exercise

Shard key.

sh.shardCollection(ns, { k: "" })

Project: Contacts Book

Exercise

Read.

db.contacts.()

Project: Blog Data

Exercise

Add comment.

{ : { comments: c } }

Project: Sales Report

Exercise

Top three.

{ $limit:  }

Security Basics

Exercise

Enable auth.

mongod --

Performance Tips

Exercise

Limit fields.

find({}, { name:  })

MongoDB Best Practices

Exercise

Back up.

Back up