Experiment 4
Connect structured data to Hadoop Environment using Sqoop.
Resources & Reference Output
BDA Lab Manual
View Document
Crowdsourced Journal Notes
Optional Reference
Reference Output Document
View Document
Author: Nishant Narudkar
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, saves time)
- 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 it - Under System Variables → click Path → Edit → New
- Add:
C:\Program Files\MongoDB\Server\8.2\bin- Click New again and add:
C:\Users\YourName\AppData\Local\Programs\mongosh(Replace YourName with your Windows username)
- Click OK on all windows
Step 6 — Verify installation
Close all terminals, open a fresh Command Prompt and 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 a second Command Prompt Window and run:
mongoshYou should see:
test>Step 9 — Paste and run the experiment
Once you see test>, paste this script:
use("exp4_mongodb");
db.createCollection("Students");
print("Collections:"); print(db.getCollectionNames());
db.StudentsInfo.insertOne({name:"Rushil", age:21, course:"BTech"});
print("\n-- After insertOne --");
db.StudentsInfo.find().forEach(printjson);
db.StudentsInfo.insertMany([
{name:"Aarav", age:22},
{name:"Ishita", age:20},
{name:"Rohan", age:25}
]);
print("\n-- After insertMany --");
db.StudentsInfo.find().forEach(printjson);
print("\n-- findOne Rohan --");
printjson(db.StudentsInfo.findOne({name:"Rohan"}));
print("\n-- findOne from wrong collection (Students) --");
printjson(db.Students.findOne({name:"Rohan"}));
db.StudentsInfo.updateOne({name:"Aarav"},{$set:{age:23}});
print("\n-- After updateOne Aarav age=23 --");
db.StudentsInfo.find().forEach(printjson);
db.StudentsInfo.deleteOne({name:"Rohan"});
print("\n-- After deleteOne Rohan --");
db.StudentsInfo.find().forEach(printjson);
db.Students.drop();
db.dropDatabase();
use("company_db");
db.employee.insertOne({
Emp_id: "1000rt",
Personal_details: {First_Name:"Rushil", Last_Name:"Mehta", DOB:"1999-05-12"},
Contact: {email:"rushil.mehta@gmail.com"},
Address: {city:"Mumbai"}
});
print("\n-- employee.find() --");
db.employee.find().forEach(printjson);
print("\n-- Projection: Address only --");
db.employee.find({}, {Address:1}).forEach(printjson);Hit Enter and everything runs.
Note:
If mongod says it's already running, skip Step 7 and go directly to Step 8.