# Up Next: Queries

Look back at what you can do after Module 1, and get a first look at Module 2, where every screen of an app becomes a query that finds, sorts, pages and changes documents.

Novice · MongoDB · Updated November 19, 2026

By Gregor Dzierzon

## After this lesson you can

- Describe the questions Module 2's queries will let you ask a collection, such as the quick dinners or the best-rated recipes

## Key takeaways

- After Module 1 you can set up MongoDB, store documents with the right shapes and types, and say when a document database fits.
- Every screen of an app asks the database a question, such as the quick dinners or the best-rated recipes, and each question is a query.
- A query's filter is itself a document, written with the braces, fields and values you know now.
- Module 2 teaches the filters, how to reach into arrays and nested documents, how to sort and page the results, and how to change and delete documents safely.

At the start of this module, a database was a word. Now you have MongoDB running on your own computer, and a recipe card you wrote from nothing, lists and nested documents and exact money included, sitting in a collection. That's the hard part of every data layer: deciding what each record looks like.

This lesson looks back at what you can do, and gives you a first look at Module 2, where you stop storing cards and start asking them questions.

## What you can do now

After Module 1, you can:

- **set up** MongoDB, mongosh and Compass, and get, check and hand in an exercise;
- **explain** the difference between tables of rows and a collection of documents, and name the NoSQL families;
- **say honestly** when documents fit an app, and when a relational database is the better choice;
- **write a document from nothing**: braces, fields and values, text in quotes, arrays in square brackets, and documents inside documents;
- **choose a type** for every value: int and double, Decimal128 for money, dates, true or false, `null`, and an `_id` of your own or an ObjectId.

Read the Banana Bread card from *BSON Types and the _id Field* again. At the start of the module, its braces, quotes and `Decimal128('0.60')` would have looked like a foreign language. Now you can read every line aloud, and say why each value has the type it has.

## Every screen is a question

Think about the pages of Sunday Kitchen's website. Each one shows some of the recipes, and each one is a question to the database:

| The screen | The question it asks |
|---|---|
| A "Quick dinners" shelf | Which dinners take 30 minutes or less? |
| A vegetarian page | Which recipes are vegetarian, and which of those use chickpeas? |
| "Our best-rated" | Which recipes have the highest ratings, best first? |
| The search results, page 2 | Which recipes match, ten to a page, starting at the eleventh? |
| A reminder for the cooks | Which recipes has nobody rated yet? |

A question asked of a database is a **query**. Every one of those screens is a query, and so is a profile page, a shopping cart and a search box in any app you'll ever build.

## A first look at a query

Here is a query on the two cards in your `cards` collection: the recipes that make 10 or more servings, showing only the name and the servings.

```mongodb
db.cards.find({ servings: { $gte: 10 } }, { name: 1, servings: 1 })
```

```text
[ { _id: 11, name: 'Banana Bread', servings: 10 } ]
```

Look at the part inside `find( )`. The filter, `{ servings: { $gte: 10 } }`, is a document: braces, a field, a colon and a value. Its value is a small document too, and `$gte` is read "greater than or equal to". You already know how to write every mark in it. Module 2 teaches what you can put inside.

## What Module 2 unlocks

Module 2 loads Sunday Kitchen's whole box, 40 recipes, in one go, and then asks them real questions:

- **Finding documents:** exact matches, ranges such as "30 minutes or less", one of a list of cuisines, either of two conditions, and the recipes with a field missing.
- **Arrays and nested fields:** the recipes tagged *vegan*, the ones under 300 calories in their nutrition box, the ones that use chickpeas from their list of ingredients; choosing which fields come back; sorting best first; and paging, ten at a time.
- **Updating and deleting:** changing a rating, adding a tag, counting a favorite, and deleting only what you meant to delete.

The exercises put each one to work, starting with *Exercise: Recipe Finder*: six of the questions above, written by you and checked by tests on the 40 recipes.

## Check yourself

2 questions to try on the lesson page.

## So what

Module 1 gave every recipe a shape. Module 2 asks the questions every screen of an app depends on, and the filters it teaches are documents, so you already know how to write them.

## Key terms

- [Query Filter](https://www.ask-codey.com/glossary/query-filter)
- [Query Operators](https://www.ask-codey.com/glossary/query-operators)

## Related

- [Adding Many Documents with insertMany](https://www.ask-codey.com/lessons/mongodb-insertmany-adding-many-documents)
- [Finding Documents with find and findOne](https://www.ask-codey.com/lessons/mongodb-find-and-findone)

Source: https://www.ask-codey.com/lessons/mongodb-up-next-queries
