Start MongoDB
sudo systemctl start mongod
Stop MongoDB
sudo systemctl stop mongod
Restart MongoDB
sudo systemctl restart mongod
MongoDB Status
sudo systemctl status mongod
Enter Mongo Shell
mongo
Connect to remote host
mongo --host <hostname or ip address> --port <port>
Example:
Connect to a specific database
mongo <host>/<database>
Example:
Log Into MongoDB
mongo -u <username> -p <password> --authenticationDatabase <dbname>
Example:
Create, select or switch database
use <database name>
Example:
Show current database
db
Show all databases
show dbs
Show all users on current database
show users
Show all roles on current database
show roles
Further Reading
Top comments (0)