MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Find Queries & Comparison Operators ($eq, $gt, $in, $nin)0%
Study Materials
MongoDB & MongooseProgress 0%
1.1Document Databases vs Relational SQL: CAP Theorem & When to Use NoSQL1.2JSON vs BSON Data Types & MongoDB Internal Storage Engine (WiredTiger)1.3MongoDB Atlas Cloud Setup, Network Whitelisting & Compass GUI
2.1Insert Operations: insertOne, insertMany & Write Concerns2.2Find Queries & Comparison Operators ($eq, $gt, $in, $nin)2.3Logical, Element & Array Query Operators ($and, $or, $exists, $all)2.4Update Operations: updateOne, updateMany & Field Modifiers ($set, $inc, $push)2.5Delete Operations, Cursors, Limit, Skip & Sorting in MongoDB
HomeTutorialsMongoDB & MongooseFind Queries & Comparison Operators ($eq, $gt, $in, $nin)
Logical, Element & Array Query Operators ($and, $or, $exists, $all)

Find Queries & Comparison Operators ($eq, $gt, $in, $nin)

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Querying data in MongoDB is accomplished using the find() and findOne() methods. Unlike SQL's SELECT * FROM table WHERE condition, MongoDB queries are expressed as JSON/BSON filter documents using specialized query operators.


1. Finding Documents: findOne() vs find()

1// 1. findOne(): Returns the first matching document (or null)
2const user = await db.collection('users').findOne({ email: 'priya@example.com' });
3 
4// 2. find(): Returns a CURSOR over all matching documents
5const cursor = db.collection('courses').find({ isPublished: true });
6const courses = await cursor.toArray(); // Convert cursor into JavaScript array

2. Comparison Operators Overview

OperatorMeaningExample
$eqEquals{ status: { $eq: 'ACTIVE' } } (or shorthand { status: 'ACTIVE' })
$neNot equals{ role: { $ne: 'banned' } }
$gtGreater than{ price: { $gt: 500 } }
$gteGreater than or equal to{ age: { $gte: 18 } }
$ltLess than{ inventory: { $lt: 10 } }
$lteLess than or equal to{ rating: { $lte: 4.5 } }
$inMatches any value in array{ category: { $in: ['Web', 'AI', 'Cloud'] } }
$ninMatches none of the values{ status: { $nin: ['ARCHIVED', 'DELETED'] } }

3. Practical Example: Querying Numeric Ranges and Inclusions

1// Find premium courses priced between 1,000 and 5,000 in specific categories
2const premiumCourses = await db.collection('courses').find({
3 category: { $in: ['Full-Stack', 'Data Science'] },
4 price: { $gte: 1000, $lte: 5000 },
5 isPublished: true
6}).toArray();
7 
8console.log(`Found ${premiumCourses.length} matching courses.`);

Querying Nested Subdocuments:

Use dot notation enclosed in quotes to query fields inside embedded subdocuments:

1// Query courses where instructor's experience is >= 5 years
2const expertCourses = await db.collection('courses').find({
3 'instructor.experienceYears': { $gte: 5 }
4}).toArray();

Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
What does collection.find() return in the MongoDB Node.js driver?
Question 2
Which comparison operator selects documents where a field matches any value specified in an array?
Question 3
How do you query a field named city located inside an embedded subdocument address in MongoDB?
Question 4
What filter matches all products whose rating is strictly greater than 4.5?
Question 5
What will collection.findOne({ email: 'nonexistent@test.com' }) return?

Next Lesson

Logical, Element & Array Query Operators ($and, $or, $exists, $all)

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Insert Operations: insertOne, insertMany & Write ConcernsLogical, Element & Array Query Operators ($and, $or, $exists, $all)

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master MongoDB & Mongoose with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext