Cmd> mongosh
test>
test> use collegedb
db.student.insertOne({"usn":1,"name":"alex","fathername":"sam","mothername
":"mary","hobbies":
["dancing","singing","movies"],"admissiontype":"cet","age":17,"income":4000
0,"skills":["c","c++","python"],"place":"kundapura","location":
{"type":"Point","coordinates":[-73.856077,
40.848447]},"college":"mitk","comments":"this is a great college"})
collegedb>
db.student.insertMany([{"usn":2,"name":"ravi","fathername":"rajesh","mothern
ame":"sandhya","hobbies":
["painting","singing","movies"],"admissiontype":"cet","age":18,"income":5000
0,"skills":["java","c++","aiml"],"place":"kundapura","location":
{"type":"Point","coordinates":[-72.856077,
41.848447]},"college":"mitk","comments":"good to learn new things"},
{"usn":3,"name":"kumar","fathername":"sathish","mothername":"priya","hobbi
es":
["painting","tv","movies"],"admissiontype":"mgt","age":17,"income":80000,"sk
ills":["java","c++","aiml"],"place":"kundapura","location":
{"type":"Point","coordinates":[-71.856077,
42.848447]},"college":"aj","comments":"great place to groom talent"},
{"usn":4,"name":"lingesh","fathername":"vinoth","mothername":"nirmala","ho
bbies":
["painting","tv","movies"],"admissiontype":"cet","age":18,"income":80000,"ski
lls":["aiml","c++","java"],"place":"kundapura","location":
{"type":"Point","coordinates":[-70.856077,
40.848447]},"college":"mitk","comments":"nice college"},
{"usn":5,"name":"chinmay","fathername":"lingappa","mothername":"kavitha","
hobbies":
["painting","tv","art"],"admissiontype":"cet","age":17,"income":80000,"skills":
["aiml","c++","python"],"place":"kundapura","location":
{"type":"Point","coordinates":[-70.856077,
40.848447]},"college":"mitk","comments":"nice college"}])
collegedb> db.student.find()
collegedb> db.student.find({"usn":1})
collegedb> db.student.find().limit(2)
collegedb> db.student.find().skip(1).limit(2)
collegedb> db.student.find({"usn":1},{"usn":1,"name":1,"_id":0})
collegedb> db.student.updateOne({"usn":1},{$set:{"marks":
[88,98,100,95,91]}})
collegedb> db.student.find({"usn":1},{"usn":1,"name":1,"marks":1,"_id":0})
Pop the last element from marks array of Usn :1
collegedb> db.student.updateOne({"usn":1},{$pop:{"marks":-1}})
collegedb> db.student.find({"usn":1},{"usn":1,"name":1,"marks":1,"_id":0})
collegedb> db.student.updateOne({"usn":1},{$push:{"marks":66}})
collegedb> db.student.find({"usn":1},{"usn":1,"name":1,"marks":1,"_id":0})
collegedb> db.student.updateOne({"usn":2},{$set:{"marks":
[95,88,77,45,55]}})
collegedb> db.student.find({"usn":2},{"usn":1,"name":1,"marks":1,"_id":0})
collegedb> db.student.find({"marks":{$elemMatch:{$gt:99}}})
collegedb> db.student.find({"marks":{$elemMatch:{$gt:55,$lt:70}}})
collegedb> db.student.find({"marks.0":{$eq:100}})
collegedb> db.student.updateMany({},{$push:{"hobbies":{$each:
["baking","surfing"]}}})
collegedb> db.student.find()
collegedb> db.student.updateOne({"usn":1},{$push:{"skills":{$each:
["it","testing"],$sort:1}}})
collegedb> db.student.createIndex({"location":"2dsphere"})
db.student.find({"location":{$near:{$geometry:{type:"Point",coordinates:[-
70.856077,40.848447]},$maxDistance:10000,$minDistance:0}}}
collegedb> db.student.createIndex({"comments":"text"})
collegedb> db.student.find({$text:{$search:"great"}})
collegedb> db.student.find({$text:{$search:"\"great college\""}})
collegedb> db.student.find({$text:{$search:"great -college"}})
collegedb> db.student.aggregate([{$group:{"_id":"$age", averageIncome:
{$avg:"$income"}}}])
collegedb> db.student.aggregate([{$group:{"_id":"$admissiontype",
averageIncome:{$avg:"$income"}}}])
collegedb> db.student.aggregate([{$group:{"_id":"$admissiontype",
minIncome:{$min:"$income"}}}])
collegedb> db.student.aggregate([{$group:{"_id":"$admissiontype",
maxIncome:{$max:"$income"}}}])
db.student.aggregate([{$match:{"age":{$lt:25}}},{$sort:{"age":1}},{$skip:1},
{$project:{"_id":0,"usn":1,"name":1,"age":1}}])