MongoDB 8 cheatsheet

MongoDB 8: Connecting and navigating

7 common MongoDB 8 tasks.

Check the shell version

Print the installed mongosh version.

mongosh --version

Connect to a local server

Open the shell against a database on the default port.

mongosh "mongodb://localhost:27017/mydb"

Connect to Atlas

Connect with a connection string and a user, prompting for the password.

mongosh "mongodb+srv://cluster0.example.mongodb.net/mydb" --username appUser

List databases

Show the databases on the server.

show dbs

Switch database

Switch to a database. It is created when you first store data.

use mydb

List collections

Show the collections in the current database.

show collections

Check the server version

Print the version of the server you are connected to.

db.version()

Was this page helpful?