Using mongosh

View saved

Start the shell

mongosh is the modern MongoDB shell. Connect, then type JavaScript-style commands.

mongosh
# or
mongosh "mongodb://127.0.0.1:27017"

Useful helpers

  • show dbs — list databases
  • use myapp — switch or create a database context
  • show collections — list collections in the current db
  • db — print the current database name

Run a tiny insert

Collections appear when you first write data. This creates notes under the current database.

use learning
db.notes.insertOne({ title: "Hello MongoDB", tags: ["intro"] })

Exit cleanly

Type exit or press Ctrl+D when you are done. Prefer scripts and drivers for app code; use mongosh for exploration and admin tasks.

Comments

One comment per signed-in account. Comments are saved with this page’s URL.