Share
Explore

Introduction to MongoDB: A Student Lab Learning Notebook

Course PowerPoint Workbook:
Loading…

Note: To install MONGO DB Shell: You must download the installer separately:
LINK to Mongo DB Shell Lab Exercises Workbook:
Loading…

MONGO DB Shell: A command line utility
Introduction to MongoDB and SQL:
MongoDB is a NoSQL database management system that stores data in JSON-like documents, allowing for flexible schemas and horizontal scaling [2].
SQL, or Structured Query Language, is a language used to communicate with a relational database management system (RDBMS) such as Oracle, Microsoft SQL Server, or MySQL [2].
RDBMS follows Codd's Rules, which provide a set of guidelines for complete relational database systems [1].

Comparative Operations:

CRUD (Create, Read, Update, Delete) operations in MongoDB are performed using commands make available through MONGO DB SHELL and MONGOOSE APIs such as insertOne, findOne, updateOne, and deleteOne [3].
In SQL, CRUD operations are performed using INSERT, SELECT, UPDATE, and DELETE statements [3].
There are 3 dialects of SQL:
Data Query Language: CRUD
DDL: create and delete columns
DCL: Data control language security enablement on SQL tables.
Aggregation operations in MongoDB are performed using the aggregation pipeline, which allows users to process documents through a series of data transformation stages, such as filtering, grouping, and sorting [3].
In SQL, aggregation operations are performed using aggregate functions like COUNT, SUM, AVG, and GROUP BY clauses [3].
Join operations in MongoDB are performed using the $lookup stage in the aggregation pipeline, which allows users to perform left outer joins on documents from another collection [3].
In SQL, join operations are performed using INNER JOIN, OUTER JOIN, and CROSS JOIN clauses [3].

Topologies:

Data organization in MongoDB is done using collections that store JSON-like documents, providing a flexible schema that allows for easy incorporation of new fields and nested data structures [2].
In SQL, data is organized using tables with a fixed schema, consisting of rows and columns [2]. Tables are memory structures created by the database server.
Indexing in MongoDB is performed using B-tree indexes, which can be created on any field within the JSON-like documents [2]. In SQL, indexing is performed using B-tree, bitmap, and hash indexes on specific columns within a table [2].
Compliance with Codd's Laws:
MongoDB does not fully comply with Codd's Laws as it is a NoSQL database and not a complete RDBMS [1]. SQL-based RDBMS, on the other hand, follow Codd's Laws more closely, with some RDBMS systems adhering to 9-12 of the 12 rules [1].

Implications and Use Cases:

MongoDB is well-suited for use cases requiring high write loads, flexible data models, and horizontal scaling, such as big data applications, content management systems, and real-time analytics [2]. SQL-based RDBMS are more appropriate for use cases requiring strong consistency, complex query capabilities, and strict data schema enforcement, such as financial systems, customer relationship management, and inventory management [2].
Understanding the differences between MongoDB and SQL-based RDBMS is crucial for making informed decisions in database management and design, as each approach has its own strengths and weaknesses [2].
References:
[3]

Learning Outcomes:

Introduce MONGO DB with the emphasis on setting up the tooling and making a simple college enrollment system database with students, classes, and how students are enrolled into classes
Introduction to MongoDB and SQL:
MongoDB is a NoSQL database management system that stores data in JSON-like documents, allowing for flexible schemas and horizontal scaling [2]. SQL, or Structured Query Language, is a language used to communicate with a relational database management system (RDBMS) such as Oracle, Microsoft SQL Server, or MySQL [2]. RDBMS follows Codd's Rules, which provide a set of guidelines for complete relational database systems [1].
Comparative Operations:
CRUD (Create, Read, Update, Delete) operations in MongoDB are performed using commands such as insertOne, findOne, updateOne, and deleteOne [3]. In SQL, CRUD operations are performed using INSERT, SELECT, UPDATE, and DELETE statements [3].
Aggregation operations in MongoDB are performed using the aggregation pipeline, which allows users to process documents through a series of data transformation stages, such as filtering, grouping, and sorting [3]. In SQL, aggregation operations are performed using aggregate functions like COUNT, SUM, AVG, and GROUP BY clauses [3].
Join operations in MongoDB are performed using the $lookup stage in the aggregation pipeline, which allows users to perform left outer joins on documents from another collection [3]. In SQL, join operations are performed using INNER JOIN, OUTER JOIN, and CROSS JOIN clauses [3].
Topologies:
Data organization in MongoDB is done using collections that store JSON-like documents, providing a flexible schema that allows for easy incorporation of new fields and nested data structures [2]. In SQL, data is organized using tables with a fixed schema, consisting of rows and columns [2].
Indexing in MongoDB is performed using B-tree indexes, which can be created on any field within the JSON-like documents [2]. In SQL, indexing is performed using B-tree, bitmap, and hash indexes on specific columns within a table [2].
Compliance with Codd's Laws:
MongoDB does not fully comply with Codd's Laws as it is a NoSQL database and not a complete RDBMS [1]. SQL-based RDBMS, on the other hand, follow Codd's Laws more closely, with some RDBMS systems adhering to 9-12 of the 12 rules [1].
Implications and Use Cases:
MongoDB is well-suited for use cases requiring high write loads, flexible data models, and horizontal scaling, such as big data applications, content management systems, and real-time analytics [2]. SQL-based RDBMS are more appropriate for use cases requiring strong consistency, complex query capabilities, and strict data schema enforcement, such as financial systems, customer relationship management, and inventory management [2].
Understanding the differences between MongoDB and SQL-based RDBMS is crucial for making informed decisions in database management and design, as each approach has its own strengths and weaknesses [2].
References:
[3]

What are my steps to setup MONGO DB

Here are the steps to install MongoDB on Windows:

Go to the MongoDB Download Center and download the MongoDB Community Server for Windows.
Run the downloaded .msi file and follow the installation wizard.
Select "Complete" as the setup type to install MongoDB and the MongoDB tools to the default location. Alternatively, select "Custom" to specify which executables are installed and where.
During the installation process, you can choose to set up MongoDB as a Windows service or just install the binaries.
After the installation is complete, add the MongoDB bin directory to your system's PATH environment variable.
Open a command prompt and run the mongod command to start the MongoDB server.
Open another command prompt and run the mongo command to start the MongoDB shell.
You can now use the MongoDB shell to create databases, collections, and documents.
Note that before deploying MongoDB in a production environment, you should consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments
.

Table of Contents

Introduction
Setting up the tooling
Creating a simple college enrollment system

Students
Classes
Enrolling students into classes
Conclusion

1. Introduction

MongoDB is a popular NoSQL database system that stores data in JSON-like documents called BSON (Binary JSON). It is highly scalable and provides excellent performance for handling large volumes of data. In this lab, we will learn how to set up the tooling for MongoDB and create a simple college enrollment system database with students, classes, and how students are enrolled into classes.

2. Setting up the tooling

To get started with MongoDB, you need to install the MongoDB server and client on your machine. Follow the instructions for your operating system on the .
Once MongoDB is installed, start the MongoDB server by running mongod in your terminal. You can interact with the MongoDB server using the mongo shell.

3. Creating a simple college enrollment system

a. Students

First, let's create a database for our college enrollment system:
use college_enrollment
Now, let's create a collection for students:
mongo
Copy code
db.createCollection("students")
To insert a student document into the students collection, use the following command:
mongo
Copy code
db.students.insert({
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com",
"enrolled_courses": []
})

b. Classes

Next, let's create a collection for classes:
mongo
Copy code
db.createCollection("classes")
To insert a class document into the classes collection, use the following command:
mongo
Copy code
db.classes.insert({
"name": "Introduction to MongoDB",
"code": "MONGO101",
"students_enrolled": []
})

c. Enrolling students into classes

To enroll a student into a class, we need to update both the student's enrolled_courses and the class's students_enrolled arrays.
First, find the student and class documents:
mongo
Copy code
var student = db.students.findOne({"email": "john.doe@example.com"})
var classToEnroll = db.classes.findOne({"code": "MONGO101"})
Then, update the student's enrolled_courses array:
mongo
Copy code
db.students.update(
{"_id": student._id},
{$push: {"enrolled_courses": classToEnroll._id}}
)
Lastly, update the class's students_enrolled array:
mongo
Copy code
db.classes.update(
{"_id": classToEnroll._id},
{$push: {"students_enrolled": student._id}}
)
Now, when you query the student and class documents, you'll see that the student has been enrolled in the class and the class has the student enrolled.

4. Conclusion

In this lab, we have learned how to set up the tooling for MongoDB and create a simple college enrollment system database with students, classes, and how students are enrolled into classes. MongoDB is a powerful tool for managing and querying large volumes of data, and its flexibility makes it a popular choice for web applications and other projects that require a scalable database system.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.