Skip to content
MQL Practice Arena // In-Memory Document Engine

MongoDB Practice Problems

Execute MQL and aggregation challenges. Validate predicates, accumulators, and output tuples directly against in-memory BSON collections.

PROGRESS:0 / 50 SOLVED (0%)
PRACTICE_CHALLENGE // EASY

Filter Active Developers

Problem Prompt(Filtering & Projection)

Write an MQL query to find all users where role is "developer" and status is "active".

Expected Output Criteria

2 documents (Bob Martinez, George Clark)

Target Collection Schema
[ { "_id": "u1", "name": "Alice Chen", "email": "alice@cloud.io", "role": "admin", "country": "US", "age": 29, "status": "active", "tags": [ "lead", "infra" ], "score": 95 }, { "_id": "u2", "name": "Bob Martinez", "email": "bob@cloud.io", "role": "developer", "country": "CA", "age": 34, "status": "active", "tags": [ "backend", "go" ], "score": 88 }, { "_id": "u3", "name": "Charlie Kim", "email": "charlie@cloud.io", "role": "developer", "country": "US", "age": 26, "status": "pending", "tags": [ "frontend", "react" ], "score": 72 } ]
Execution Output
READY_FOR_EVALUATION: Press "Evaluate Challenge" to test query against users collection.

All 50 Practice Challenges

mp-1

Filter Active Developers

Write an MQL query to find all users where role is "developer" and status is "active".

Easy
mp-2

High-Value Orders Filter

Find all orders where total is strictly greater than 500.

Easy
mp-3

Project Customer Names & Credit

Find all customers with tier = "Enterprise", projecting only the name and creditLimit fields (suppress _id).

Easy
mp-4

Low-Stock Inventory Scan

Select all products whose current stock is less than 20 units.

Easy
mp-5

Audio Hardware Catalog

Find all products in category "Audio".

Easy
mp-6

US Infrastructure Nodes

Query all servers provisioned in region "us-east".

Easy
mp-7

Pending Orders Audit

Find all orders where status is either "shipped" or "cancelled".

Easy
mp-8

Nested Contact Email Filter

Find all customers whose nested contact.email ends with ".com" or matches domain acme.com.

Easy
mp-9

High-Density Compute Fleet

Select all servers with 32 or more CPU cores (cores >= 32).

Easy
mp-10

Canadian & German Customers

Find all customers residing in country "CA" or "DE".

Easy
mp-11

Active High-Rated Products

Find all products that are active (active = true) and have a rating >= 4.7.

Easy
mp-12

Senior Age Filter

Find all users with age strictly greater than 30.

Easy
mp-13

Wire Payment Transactions

Find all orders where payment method is "wire".

Easy
mp-14

Maintenance Fleet Nodes

Select all servers whose status is NOT "active".

Easy
mp-15

Customer Credit Directory

Select all customer accounts with creditLimit >= 50000.

Easy
mp-16

Array Tag Membership Filter

Find all users who have the tag "backend" inside their tags array.

Intermediate
mp-17

Sorted & Limited Price Search

Find all active products, sorted by price in descending order (-1), limiting the result to the top 3 most expensive items.

Intermediate
mp-18

Multiple Array Tags ($all)

Find all servers that have BOTH "k8s" AND "api" tags in their tags array.

Intermediate
mp-19

Count Completed Orders by Category

Run an aggregation pipeline on orders to filter status = "completed" and count the number of orders in each category.

Intermediate
mp-20

Total Revenue by Payment Method

Aggregate orders to compute total revenue ($sum of total) grouped by payment method, sorted descending by totalRevenue.

Intermediate
mp-21

Customer Lifetime Spend by Tier

Aggregate customers where active = true, grouping by tier to find the average credit limit (avgCredit) rounded or calculated via $avg.

Intermediate
mp-22

Nested Hardware Specification Filter

Find all products where the nested subdocument specs.ram is greater than or equal to 32.

Intermediate
mp-23

Pagination with Skip and Limit

Sort all users by score descending (-1), skip the first 2 users, and limit the result to 3 users.

Intermediate
mp-24

Unwind Tags and Count Frequency

Deconstruct the users tags array using $unwind, and count how many users have each individual tag.

Intermediate
mp-25

Average Order Value by User

Group all orders by user_id to compute the total spend (totalSpent) and average order value (avgTotal).

Intermediate
mp-26

Server Core Density Analysis

Group servers by region, calculating the total number of CPU cores (totalCores) and total RAM (totalRam) per region.

Intermediate
mp-27

Project Computed Value with $project

Aggregate products projecting only the product name and a computed field inventoryValue (price multiplied by stock). Suppress _id.

Intermediate
mp-28

Multiple Criteria Exclusion with $nor

Find all users where status is NOT "pending" AND country is NOT "DE".

Intermediate
mp-29

Unique Product Categories Set

Use a single $group stage with _id: null to extract a deduplicated array of all product categories using $addToSet.

Intermediate
mp-30

Order Quantity Minimum and Maximum

Group orders by category, finding the minimum total (minTotal) and maximum total (maxTotal) in each category.

Intermediate
mp-31

Left Outer Join Orders with Customers

Execute an aggregation on orders joining the users collection on user_id = u._id using $lookup, outputting the user details in a field named customerDetails.

Advanced
mp-32

Top Spenders Ranking Pipeline

Aggregate orders where status = "completed", group by user_id to compute totalSpent, sort by totalSpent descending, and limit to top 2 spenders.

Advanced
mp-33

Filtered Array Projection with $elemMatch

Find all users who possess an array element matching a tag ending in "end" (backend or frontend).

Advanced
mp-34

Filter Join Results ($unwind + $match)

Join orders with users, unwind customer, and retain only transactions where the customer's country is "CA".

Advanced
mp-35

Multi-Condition Complex Filter

Find all orders where total > 200 AND category is NOT "Hardware" AND status = "completed".

Advanced
mp-36

Global Hardware Load Average Analysis

Filter active servers, and compute the global average loadAvg (avgLoad) and max loadAvg (peakLoad) across all active nodes.

Advanced
mp-37

Conditional Category Flagging ($cond)

Use $project or $set with $cond to project products with an added flag isExpensive (true if price >= 500, else false).

Advanced
mp-38

Top Product Per Category Discovery

Sort products by price descending, then group by category using $first to select the most expensive product in each category.

Advanced
mp-39

Pushing Order IDs by Customer

Group orders by user_id, pushing all order _id values into an array named orderHistory, along with orderCount.

Advanced
mp-40

Regional Compute Fleet Load Ranking

Group servers by region, finding total compute resources and sorting by total cores descending.

Advanced
mp-41

Active High-Capacity Enterprise Search

Find active Enterprise customers located in US or UK with credit limit greater than 60,000.

Advanced
mp-42

Multi-Role User Search

Find all users who are either an "admin" OR have a score strictly greater than 90.

Advanced
mp-43

Multi-Faceted Dashboard Aggregation ($facet)

Run an aggregation on orders using $facet to calculate both: 1. "byStatus": total count grouped by status, and 2. "overview": overall total revenue across all orders.

Expert
mp-44

Enterprise Customer Order Value Audit

Join customers with orders, filter for customers where tier = "Enterprise", unwind orders, and compute the total spend per enterprise customer.

Expert
mp-45

Price Range Bucketing ($bucket)

Partition products into three price tiers using $bucket: [0, 200), [200, 700), and [700, 3000). Count products and average price in each.

Expert
mp-46

Covered Query Verification

Execute a covered query on users finding by email, projecting only email and suppressing _id ({ _id: 0, email: 1 }).

Expert
mp-47

Customer Average Rating Analysis

Group products by category, projecting category name, totalStock ($sum: stock), and rounding or averaging rating.

Expert
mp-48

Complex Multi-Stage Revenue Pipeline

Filter orders where total >= 200, group by category to find revenue and item count, and sort by revenue descending.

Expert
mp-49

Tag Popularity Unwind and Filter

Unwind user tags, group by tag to count occurrences, and filter for tags shared by 2 or more users ($match: count >= 2).

Expert
mp-50

End-to-End Infrastructure Audit

Filter servers where status = "active", group by region to compute nodeCount, totalCores, and average loadAvg (avgLoad), sorted by nodeCount descending.

Expert