Experiment 5
Implement CRUD operations using any NOSQL Datastore.
Resources & Reference Output
BDA Lab Manual
View Document
Output Document
View Document
Author: Kaniikesh
Journal Writing Part to refer (Made easy)
View Document
Provided to us by Peeyush Hota for making writing part and programs easier. Ignore the Code while writing in your Journal.
Step 1 — Download MongoDB
-
Select:
- Version: 8.2.5
- Platform: Windows
- Package: msi
-
Click Download
Step 2 — Install MongoDB
- Double-click the
.msifile - Click Next → Accept license → Choose Complete
- On Service Configuration leave everything default
- Uncheck MongoDB Compass (optional)
- Click Install → Finish
Step 3 — Download & Install mongosh
- Go to: https://www.mongodb.com/try/download/shell
- Select Windows → MSI
- Download → double-click → Next → Install → Finish
Step 4 — Create the data folder
Open Command Prompt as Administrator and run:
mkdir C:\data\dbStep 5 — Add MongoDB to PATH
- Press Win + S
- Search Environment Variables
- Open Edit the system environment variables
- Click Environment Variables
Under System Variables
- Select Path
- Click Edit
- Click New and add
C:\Program Files\MongoDB\Server\8.2\binAdd another path:
C:\Users\YourName\AppData\Local\Programs\mongoshReplace YourName with your Windows username.
Click OK on all windows.
Step 6 — Verify installation
Close terminals and open a new Command Prompt.
Run:
mongod --version
mongosh --versionBoth should print version numbers.
Step 7 — Start MongoDB server
Open Command Prompt Window 1 and run:
mongodLeave this window open.
Step 8 — Open mongosh
Open Command Prompt Window 2 and run:
mongoshYou should see:
test>Step 9 — Paste and run the Experiment 5 script
Once you see test>, paste this script:
use("CRUD_DB");
db;
// Insert one
db.students.insertOne({name:"Rushil", age:21, course:"BTech"});
// Insert many
db.students.insertMany([
{name:"Aarav", age:22, course:"AIML"},
{name:"Ishita", age:20, course:"CSE"}
]);
// Find all
print("\n-- find() --");
db.students.find().forEach(printjson);
// find().pretty()
print("\n-- find().pretty() --");
db.students.find().forEach(printjson);
// Delete Rushil
db.students.deleteOne({name:"Rushil"});
print("\n-- After deleteOne Rushil --");
db.students.find().forEach(printjson);
// Update Aarav age to 23
db.students.updateOne({name:"Aarav"}, {$set:{age:23}});
print("\n-- After updateOne Aarav age=23 --");
db.students.find().forEach(printjson);
// find().pretty() again after update
print("\n-- find().pretty() after update --");
db.students.find().forEach(printjson);Press Enter and all commands will run sequentially.
Note:
If mongod says MongoDB is already running, skip Step 7 and directly open mongosh.