MongoDB
Documents, collections, queries and access control.
Level 101 · 18 lessons · 15 practice labs
Lessons
Getting started
- Installing MongoDB and connecting with mongosh: You will install a MongoDB server, connect with the mongosh shell and run your first commands.
- MongoDB databases and collections: You will understand databases and collections in MongoDB and what it means to work with documents instead of tables.
- Inserting documents in MongoDB: You will add one or many documents to a MongoDB collection and see the identifier given to each.
- MongoDB BSON types, dates, arrays, embedded documents: You will recognise the data types MongoDB stores, including dates, arrays and embedded documents.
- Short task: a bookshop’s product collection
Queries and changes
- MongoDB queries and filter operators: You will use MongoDB filter operators to find only the documents in a collection that match a condition.
- MongoDB array queries: $elemMatch, $in and $all: You will filter documents that hold lists and test whether one single element meets several conditions at once.
- MongoDB sorting, limiting and projection: You will sort MongoDB results, limit how many come back and fetch only the fields of a document you need.
- Updating documents in MongoDB: You will change fields in existing MongoDB documents and write a careful filter so you do not affect more documents than intended.
- Deleting documents in MongoDB: You will delete MongoDB documents and check what will be removed before a deletion that cannot be undone.
- Finding bad data in MongoDB: $type and $exists: You will find documents with wrong types or missing fields and move them to a separate collection for review.
- Cleaning data with update pipelines: You will fix wrong numbers and text in one updateMany command with conditional expressions, then add a validation rule.
- Short task: find and fix bad records
Design, speed and security
- MongoDB schema design and references: You will learn to decide in MongoDB whether data belongs inside one document or in a separate document linked by a reference.
- MongoDB validation: $jsonSchema: You will use $jsonSchema in MongoDB to set which fields and types a collection accepts, and block bad data at the door.
- MongoDB indexes and explain: You will see how MongoDB indexes speed up searches and use explain to inspect how a query runs.
- MongoDB aggregation pipelines and $lookup: You will use MongoDB aggregation pipelines, which process and summarise data step by step, and $lookup, which brings in information from another collection.
- Capstone: a catalogue with access control in MongoDB: You set up a fictional company's product catalogue in MongoDB, create users and give each only the role it needs.
Practice labs
- Add the first documents to a book collection: Insert five books with author, price and a tag array for Defne Bookshop using insertMany, then query them.
- Convert dates stored as strings into real dates: Convert dates stored as strings in an events collection to the Date type and show that range queries now work.
- Make a nested address structure consistent: Move address data, stored as flat fields in some documents and embedded documents in others, to one shape.
- Filter products in a price range: Fetch in-stock products between 100 and 250 lira from the Mavikuş Market catalogue, returning only name and price.
- Match two conditions on the same array element: Use $elemMatch to find products where a single review has both a score above 4 and a "verified" flag.
- Fix an array query that returns wrong results: Find why a tag query that should match all tags matches by order instead, and fix it using $all versus $in.
- Apply a bulk price increase: Raise all prices in one category by 8 per cent with $mul and verify the number of changed documents.
- Update one element inside an array: Change the status of only the returned item among an order's lines with the positional operator.
- Catch documents about to be deleted by mistake: Before running a broad deleteMany, measure its effect with countDocuments, narrow the filter and delete safely.
- Find documents with missing fields: List customer records whose e-mail is missing or empty using $exists.
- Sort out prices stored with the wrong type: Find prices entered as strings with $type and convert them to numbers with an update pipeline.
- Normalise phone numbers to one format: Clean phone numbers typed in different ways with an update pipeline and report the records still invalid.
- Add a simple schema rule to a collection: Define a $jsonSchema rule that makes name and e-mail mandatory in a members collection and try a bad insert.
- Add an index to a slow product search: Add an index to a category search that shows COLLSCAN in explain and compare documents examined.
- Join orders with customer names: Write a pipeline that adds the customer name to orders with $lookup and totals them by city.
About this course
Documents, collections, queries and access control.
What you will learn
- Getting started
- Queries and changes
- Design, speed and security
Prerequisites
No prior knowledge is needed; the course starts from zero.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at beginner level; every term is explained where it first appears.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.