In this tutorial, I will show you the basic commands of MongoDB Shell.
1. Display the database you are using
# for example, I'm currently in the netflix_movie database
> db
< netflix_movie
2. Switch databases
Notice: When you switch databases, the database does not have to be there. For example, although the database airbnb does not exist, the command still can execute successfully.
> use airbnb;
< switched to db airbnb
3. Show all databases
Notice: Only the netflix_movie database is created by me, the rest are created my MongoDB automatically.
> show databases
< admin 40.00 KiB
config 108.00 KiB
local 40.00 KiB
netflix_movie 8.00 KiB
4. Show all collections
For example, I have two collections called movies and ratings in the database.
> show collections
< movies
ratings
5. Terminate a running command
To terminate a running command or query in mongosh
, press Ctrl + C
.