Prac 3

 3A)use dbs1

> db.createCollection ("Student")

> db. Student.insertMany([{"Name":"Ajay", "Age": 25, "Department":"IT", "City": "Mumbai", "Stipend":4000),{"Name":"Amir", "Age":24, "Department": "IT", "City":"Navi Mumbai", "Stipend": 5000), {"Name": "Ranveer", "Age":21, "Department":"CS", "City": "Palghar", "Stipend":16000), ("Name":"Rajkumar", "Age":26, "Department":"CS", "City":"Navi Mumbai", "Stipend":6000), {"Name": "Kriti", "Age":30,"Department": "IT", "City": "Palghar", "Stipend":3000),{"Name":"Ayesha", "Age":27, "Department":"CS", "City": "Mumbai", "Stipend":6000}])

db. Student.aggregate({$group: {_id:"$City", Age: {$max:"$Age"}}})

db. Student.aggregate({$group: {_id:"$City", Age: {$min:"$Age"}}})

db. Student.aggregate({$group: {_id:"$City", Age: {$sum:"$Age"}}})

db. Student.aggregate({$group: {_id:"$City", Stipendavg: {$avg:"$Stipend"}}})



3B)db.createCollection ("Order")

db.Order.insertMany([{"OrderId":101, "Product":"Shoes", "Quantity":1,"Price":500}, {"OrderId":102, "Product": "Sandal", "Quantity":2,"Price":500}, {"OrderId":103, "Product":"Shoes","Quantity":2,"Price":1000}])

db.Order.aggregate ([{$group: {_id:"$Product", Quantities: {$push: "$Quantity"}}}])

db.Order.aggregate ([{$group: {_id:"$Product", Unique_Price: {$addToSet:"$Price"}}}])




3C)db.OrderRecords.insertMany ([{"CusID":101, "OrderDate": ISODate("2025-07-01"), "Amount":250}, {"CusID":102, "OrderDate": ISODate("2025-07-18"),"Amount":500}, {"CusID":181, "Order Date": ISODate("2025-07-15"), "Amount":1000}])

db.OrderRecords.aggregate([{$group:{_id:"$CusID",First_OrderDate:{$first:"$OrderDate"},Last_OrderDate:{$last:"$OrderDate"}}}})

Comments

Popular posts from this blog

Prac 5

Prac 1