MongoDB Shell is a Command Line Interface (CLI) application which manages the NoSQL, in particularly, MongoDB.
You can write and execute Javascript in MongoDB Shell.
"/usr/local/bin/mongodb"
"bin"
folder inside mongodb folder, for example, "/usr/local/mongodb/bin"
mongo --nodb
MongoDB shell version v4.2.1 >
, then you are successful.Open Shell, and type
mongo "mongodb+srv://{cluster address}" --username {username}
You replace the cluster address and username by your defined ones.
Example: mongo "mongodb+srv://learning-5jamo.mongodb.net/test" --username admin
Note
While connecting to your MongoDB Atlas cluster, or any MongoDB server, from the mongo shell, you may see the following warning message:
... WARNING: shell and server versions do not match
This warning message can be safely dismissed for the purposes of this course. The purpose of this message is to let you know that the version of the server/cluster that you are connecting to has a different version then the one of your client mongo shell. Given the different versions between server and client, there might be some incompatibility commands/features not supported by either the client shell or the server. However, in this course, you will not encounter any such issue.
If you encounter below error while connecting to an atlas cluster, please exit the Mongo shell (if you are in one) by typing quit(). You need to run the command from your command-line interface.
2019-01-11T13:35:53.633-0500 E QUERY [js] SyntaxError: missing ; before statement @(shell):1:6
These are some basic queries to control your database.
show databases
to show all databases in this cluster
use {database name}
to use this database
show collections
to show all collections in this database
db.{collection name}.find().pretty()
to list all documents in this collection
For more queries, read MongoDB Query Language