Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

mongosh-basics

mongosh basics

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
beginner

This lesson

This lesson teaches mongosh basics: document modeling, query operators, and aggregation patterns for MongoDB.

Teams query mongosh basics on every MongoDB codebase—skipping it leaves gaps in debugging and data reviews.

You will apply mongosh basics in contexts like: Content catalogs, event logs, mobile sync backends, and polyglot stacks beside SQL services.

Copy JavaScript shell queries from each lesson into mongosh or MongoDB Atlas Data Explorer—inspect matched documents and explain plans. The in-browser lab (execution_profile: none) ships later; mongosh is the practice path now. Also run db.runCommand({ ping: 1 }) first to confirm connection.

When you can explain the previous lesson's ideas without copying example queries verbatim.

mongosh is the interactive shell for MongoDB. JavaScript expressions control flow; database methods live on db.

Connection and help

// Shell:
mongosh 'mongodb://localhost:27017/practice'

// Inside mongosh:
help
db.help()
db.products.help()

Practice: Run in mongosh on your practice database.

Switching context

show dbs
use practice
db.getName()
db.stats()

Running queries

const cursor = db.products.find({ price: { $gte: 10 } })
cursor.toArray()
cursor.count()

In apps, use drivers with async APIs; mongosh is for learning and ops.

Important interview questions and answers

  1. Q: db vs database name?
    A: db is the current database handle—methods like find run on collections.
  2. Q: Semicolon in mongosh?
    A: Often optional for one-liners; use when chaining multiple statements.

Self-check

  1. How do you switch databases?
  2. What object exposes collection methods?

Pitfall: Wrong database context—always check db.getName() before destructive ops.

Interview prep

db object?
Handle for current database; exposes collection methods.
use practice?
Switches database context for subsequent commands.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • use vs show dbs?
  • Cursor vs array?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump