0
0
MongoDBquery~30 mins

$gt and $gte for greater than in MongoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
$gt and $gte for greater than in MongoDB
📖 Scenario: You are managing a small online bookstore database. You want to find books with prices greater than certain amounts to offer special discounts.
🎯 Goal: Build MongoDB queries using $gt and $gte operators to filter books by price.
📋 What You'll Learn
Create a collection named books with specific book documents
Add a variable to hold a price threshold
Write a query using $gt to find books priced greater than the threshold
Write a query using $gte to find books priced greater than or equal to the threshold
💡 Why This Matters
🌍 Real World
Filtering products or items in a database by price or other numeric values is common in e-commerce and inventory management.
💼 Career
Understanding MongoDB query operators like $gt and $gte is essential for backend developers and data analysts working with NoSQL databases.
Progress0 / 4 steps
1
DATA SETUP: Create the books collection with 4 books
Create a MongoDB collection called books with these exact documents: { title: "Book A", price: 15 }, { title: "Book B", price: 20 }, { title: "Book C", price: 25 }, { title: "Book D", price: 30 }
MongoDB
Need a hint?

Use db.books.insertMany([...]) with the exact book documents.

2
CONFIGURATION: Set a price threshold variable
Create a variable called priceThreshold and set it to 20
MongoDB
Need a hint?

Use const priceThreshold = 20 to set the threshold.

3
CORE LOGIC: Query books with price greater than priceThreshold using $gt
Write a MongoDB query called booksGreaterThan that finds all books where price is greater than priceThreshold using the $gt operator
MongoDB
Need a hint?

Use db.books.find({ price: { $gt: priceThreshold } }) to find books priced greater than the threshold.

4
COMPLETION: Query books with price greater than or equal to priceThreshold using $gte
Write a MongoDB query called booksGreaterOrEqual that finds all books where price is greater than or equal to priceThreshold using the $gte operator
MongoDB
Need a hint?

Use db.books.find({ price: { $gte: priceThreshold } }) to find books priced greater than or equal to the threshold.