MongoDB

Stage 1 · Lesson 6 of 8

mongosh, the MongoDB shell

Documents and your setup

is the MongoDB shell: a command-line client where you type commands and see results. It is built on , so it understands JavaScript, and every example in this roadmap outside the application stage uses its syntax so it works whatever language you choose.

Connect with a , then learn the basics: show dbs, use shop, show collections, db.products.findOne() and exit. db always means the current database. find() shows 20 documents at a time; type it for more.

You can also run a script file with load("seed.js"). Servers, and deployment scripts rarely have a graphical tool, so this is the client you will always have.

Common traptyping use shop and assuming the database exists: MongoDB creates it only when you first write data into it.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with

  • CourseFree
    MongoDB University

    MongoDB

    Free: start with the introduction to MongoDB and Atlas setup lessons, which use the same sample data

Practise

  • Paste a few documents and a query and run it in the browser, no install needed

Keep handy

  • The mongosh docs: connecting, running scripts and the shell helpers such as show and use

  • The Compass docs for the Schema, Explain Plan and Aggregations tabs you will use later

Also worth your time

Mark this stage as not done?