Command Operations in MongoDB
This lesson introduces all of the basic Mongo Shell command operations that can be performed (e.g., creating, reading, updating and deleting from a database).
CRUD operations from the shell
Once the MongoDB server is up and running, one can connect to it using Mongo shell client. On the terminal, on our platform, the server automatically connects, so that you don’t have to set it up.
All the functionalities that are provided in the shell client are provided through MongoDB drivers too. Drivers are provided for all popular programming languages, which means that all features that are shown in this chapter can (and should) be done through the code. However, for demonstrative purposes, the shell client is used.
Note: To get a good understanding of all the commands, and for good practice, make sure to try out all of the commands in this lesson in the terminal provided at the end of this lesson.
It’s important to note that MongoDB commands are case-sensitive.
Using mongo
To start the shell client, type the following command in the terminal :
mongo
mongo
Running the above command in the terminal should give the following result:
You’ll see that the client displays some basic information, such as client and server versions. Finally, the shell client brings the user to a prompt, where commands may be typed.
Creating a Database
At the top of the hierarchy, in the MongoDB server, is database entity. There can be multiple databases on a single server.
To create a database, MongoDB provides the command:
use DATABASE_NAME
use DATABASE_NAME
This ...