WebDev Week 10 PPT - Connecting to Databases
WebDev Week 10 PPT - Connecting to Databases
“CONNECTING TO DATABASES”
Presented by Date
Ocean Blue Shark 19 November, 2024
WHAT ARE DATABASES?
A database is like a digital filing cabinet where data is
stored, organized, and accessed when needed. Whether it’s
keeping track of friends on social media or managing
items in an online store, databases are behind the scenes
making everything work smoothly.
Also, download the MongoDB Shell from Tools. Make sure you choose
“msi” in the package.
Step 2. Setting up
Click “Next”.
Step 2. Setting up cont.
mongosh
Create a Database:
use myDatabase
Step 3. Set Up a MongoDB Database
Create a Collection:
List Databases:
show dbs
In SQL:
Performed using the INSERT command (e.g., INSERT INTO table_name VALUES (...)).
In NoSQL:
Commands like db.collection.insertOne() in MongoDB allow inserting data into collections.
READ
Purpose:
Retrieves existing data for viewing or processing.
In SQL:
The SELECT command is used (e.g., SELECT * FROM table_name).
In NoSQL:
Use db.collection.find() in MongoDB to fetch documents.
UPDATE
Purpose:
Modifies existing data entries in the database.
In SQL:
Executed with the UPDATE command (e.g., UPDATE table_name SET column=value
WHERE condition).
In NoSQL:
MongoDB provides db.collection.updateOne() or db.collection.updateMany() for updates.
DELETE
Purpose:
Removes unwanted or outdated data from the system.
In SQL:
Achieved through the DELETE command (e.g., DELETE FROM table_name WHERE
condition).
In NoSQL:
MongoDB uses db.collection.deleteOne() or db.collection.deleteMany() to remove
documents.
BEST PRACTICES FOR CRUD
OPERATIONS
Data Validation: Ensure the input data is correct
before executing CRUD commands to maintain
database integrity.
SQL Example:
SQL Example:
SQL Example:
SQL Example:
This will initialize node.js within that folder and create a new package.json file.
After initialization, type this:
This will install express and create multiple files within the folder.
CONNECTING EXPRESS.JS WITH A DATABASE (USING MONGOOSE)
The connection status must be ‘1’, if not, refer below for precise
tracking:
0: Disconnected
1: Connected
2: Connecting
3: Disconnecting
THANK YOU!
OCEAN BLUE SHARK
Carable, Luisa R.
De Jesus, Edhiev Harold Ken O.
Iruguin, Angel Jasmin G.
Nogot, Josephine Claire G.