MongoDB - Lab 1
In this lab session, we will explore MongoDB by setting up a Docker MongoDB instance using the provided command. We will cover the following:
- Launching a Docker MongoDB Container
- Connecting to the MongoDB Instance using the MongoDB Shell (mongosh)
- Creating a Database and a Collection
- Inserting and Querying Documents
1. Starting MongoDB
Steps
- Start up Docker
- Open your Terminal
-
Execute the following command
Info
This command creates a Docker container named "mongodb-instance" running the MongoDB image, mapping port 27017 on your host to port 27017 inside the container, and running MongoDB in the background.
Expected results
- The terminal will show the container ID
2. Connecting to the MongoDB Instance
Steps
- Open the Terminal (or stay in the same Terminal window)
- Execute the following command
Expected results
-
The following information in the Terminal
3. Create a database and a collection
Steps
-
Create a database named
workspace
by running the following command in the MongoDB Shell -
Create a collection called
people
by running the following command in the MongoDB Shell
Expected results
-
Two logs in your Terminal related to the previous commands
4. Inserting and Querying Documents
Steps
-
Insert the following documents to the
people
collection, using the MongoDB Shell -
Query the documents, to prove that they were successfully inserted, by running the following command into the MondBD Shell
Expected results
-
The following information in the Terminal