q1_mongo
q1_mongo
insertMany([
{ sid: 1, sname: "Ajit", school: "Xavier", hobby: "Dance", std: 5, gender: "m" },
{ sid: 2, sname: "Alisha", school: "Sharda", hobby: "Singing", std: 5, gender:
"f" },
{ sid: 3, sname: "Pratixa", school: "Aone", hobby: "Cricket", std: 5, gender: "f"
},
{ sid: 4, sname: "Deepam", school: "HBK", hobby: "Painting", std: 6, gender:
"f" },
{ sid: 5, sname: "Nisha", school: "SantKabir", hobby: "Cricket", std: 7, gender:
"f" },
{ sid: 6, sname: "Anya", school: "Xavier", hobby: "Singing", std: 6, gender:
"f" },
{ sid: 7, sname: "Raj", school: "Aone", hobby: "Painting", std: 6, gender: "m" },
{ sid: 8, sname: "Monish", school: "Sharda", hobby: "Karate", std: 6, gender: "m"
},
{ sid: 9, sname: "Ram", school: "Aone", hobby: "Dance", std: 6, gender: "m" },
{ sid: 10, sname: "Shyam", school: "SantKabir", hobby: "Singing", std: 6, gender:
"m" },
{ sid: 11, sname: "Kavisha", school: "Xavier", hobby: "Swimming", std: 7, gender:
"f" },
{ sid: 12, sname: "Nayan", school: "Aone", hobby: "Cricket", std: 7, gender:
"m" },
{ sid: 13, sname: "Meet", school: "Somlalit", hobby: "Cricket", std: 7, gender:
"m" },
{ sid: 14, sname: "Urvi", school: "Sharda", hobby: "Dance", std: 7, gender:
"f" },
{ sid: 15, sname: "Kunj", school: "Xavier", hobby: "Singing", std: 8, gender: "m"
}
]);
Retrieve the list of Name, School, and Std of all the mystudentss.
Find the name of the mystudents whose name starts with ‘R’.
Find the name of the mystudents whose name starts with vowels.
Find the name of the mystudents whose name starts with consonants.
Display all the records in ascending order of the school name and descending order
of the number.
db.mystudents.find().sort({ school: 1, std: -1 });
db.mystudents.distinct("school");
db.mystudents.countDocuments();
db.mystudents.distinct("fees");
db.mystudents.aggregate([
{ $group: { _id: null, maxFees: { $max: "$fees" }, minFees: { $min: "$fees" },
sumFees: { $sum: "$fees" } } }
]);
Display mystudentss by result in ascending order.
db.mystudents.aggregate([
{ $addFields: { totalMarks: { $add: ["$maths", "$sci", "$eng"] } } },
{ $sort: { totalMarks: 1 } }
]);
Change fees for the mystudents with the last rank to 10000.