DEV Community

Cover image for MongoDB Query Practice Guide with Real Job Portal Dataset
Nasrullah Sheikh Noman
Nasrullah Sheikh Noman

Posted on

MongoDB Query Practice Guide with Real Job Portal Dataset

Overview

Recently, I practiced MongoDB queries using a sample Job Portal database.

Instead of learning operators in isolation, I used a realistic Job Portal dataset to better understand how MongoDB queries work in real-world applications.


Dataset Structure

A sample jobs collection was created with fields such as:

  • title
  • company
  • location
  • salary
  • experience
  • skills
  • applicants
  • status
  • department

Example Document

{
  title: "\"Software Engineer\","
  company: "TechCorp Bangladesh",
  salary: 75000,
  skills: ["JavaScript", "Node.js", "MongoDB"]
}
Enter fullscreen mode Exit fullscreen mode

Topics Covered

1. Comparison Operators

Used for filtering documents based on value comparison.

Operators covered:

  • $eq
  • $ne
  • $gt
  • $gte
  • $lt
  • $lte

Example:

db.jobs.find({
  salary: { $gt: 70000 }
})
Enter fullscreen mode Exit fullscreen mode

2. Logical Operators

Combining multiple query conditions.

Operators covered:

  • $and
  • $or
  • $not
  • $nor

Example:

db.jobs.find({
  $or: [
    { location: "Dhaka" },
    { isRemote: true }
  ]
})
Enter fullscreen mode Exit fullscreen mode

3. Array Query Operators

Working with array fields such as skills.

Operators covered:

  • $in
  • $nin
  • $all
  • $size
  • $elemMatch

Example:

db.jobs.find({
  skills: { $all: ["Python", "SQL"] }
})
Enter fullscreen mode Exit fullscreen mode

4. Update Operators

Updating existing documents.

Operators covered:

  • $set
  • $inc
  • $push
  • $pull

Example:

db.jobs.updateOne(
  { title: "Frontend Developer" },
  { $push: { skills: "TypeScript" } }
)
Enter fullscreen mode Exit fullscreen mode

5. Projection, Sorting & Pagination

Topics covered:

  • Field selection
  • Sorting
  • Limiting results
  • Pagination

Example:

db.jobs.find({}, { title: 1, salary: 1, _id: 0 })
  .sort({ salary: -1 })
  .limit(5)
Enter fullscreen mode Exit fullscreen mode

6. Aggregation Pipeline

Used for analytics and reporting.

Operators covered:

  • $match
  • $group
  • $project
  • $sort

Example use case:

Calculate average salary by department.


7. Advanced Aggregation

Production-level query operations.

Operators covered:

  • $lookup
  • $unwind
  • $facet

Useful for:

  • Joining collections
  • Dashboard analytics
  • Multi-stage reporting

Key Learning

MongoDB becomes significantly easier to understand when practiced using realistic datasets instead of isolated examples.


Next Learning Goals

  • MongoDB Indexing
  • Mongoose ODM
  • MongoDB Atlas
  • Transactions

Thanks for reading.

mongodb #backend #nodejs #database #webdev

Top comments (0)