0% found this document useful (0 votes)
1 views2 pages

Crud

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Crud

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Hands-on One: CRUD Operations

use schoolDB

db.students.insertMany([
{ student_id: "S001", name: "Joy", age: 21, track: "Web" },
{ student_id: "S002", name: "Kevin", age: 19, track: "Python" },
{ student_id: "S003", name: "Zahara", age: 22, track: "AI" },
{ student_id: "S004", name: "Brian", age: 23, track: "DevOps" },
{ student_id: "S005", name: "Lilian", age: 20, track: "MERN" }
])

//Hands-on Two: Enhance students with Embedded Contacts

db.students.updateMany({}, {
$set: {
contact: { email: "user@example.com", phone: "07000111222"},
emergency: { name: "Parent", relation: "Mother", phone: "07111222333"}
}
})

//Hands-on Three: Courses $ Mentors with Referencing

db.mentors.insertMany([
{ mentor_id: "M001", name: "Mr. Kasongo", specialty: "Wantam" },
{ mentor_id: "M002", name: "Mr. WiggyG", specialty: "Truthful" },
{ mentor_id: "M003", name: "Mr. Dedan", specialty: "AI" }
])

db.courses.insertMany([
{ course_id: "C101", title: "Lyingtology", duration_weeks: 5, mentor_id: "M001"
},
{ course_id: "C102", title: "Poet", duration_weeks: 2, mentor_id: "M002" },
{ course_id: "C103", title: "AI for beginners", duration_weeks: 3, mentor_id:
"M003" }
])

//Hands-on Four: Connect everything together with enrollments (Analytics)

db.enrollments.insertMany([
{ student_id: "S001", course_id: "C101", status: "in-progress", score: 88 },
{ student_id: "S002", course_id: "C102", status: "completed", score: 92 },
{ student_id: "S004", course_id: "C101", status: "in-progress", score: 78 },
{ student_id: "S005", course_id: "C103", status: "completed", score: 85 }
])

//Aggregation: Students per course


db.enrollments.aggregate([
{ $group: { _id: "$course_id", total_students: { $sum: 1 } } }
])

//Aggregation: Average score per course


db.enrollments.aggregate([
{ $group: {_id: "$course_id", avg_score: { $avg: "$score" } } }
])
//Aggregation: Students per track
db.students.aggregate([
{ $group: { _id: "$track", total_students: { $sum: 1 } } }
])

//Aggregation: Average age per track


db.students.aggregate([
{ $group: { _id: "$track", avg_age: { $avg: "$age" } } }
])

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy