Mongo Queries 4
Mongo Queries 4
crud> db.createCollection("operate")
crud> db.operate.insert({
... enroll:"1011",
... name:"bhakti",
... college:"VCET",
... course:{
... courseName:"COMP",
... duration:"4 years",
... },
... address:{
... city:"mumbai",
... state:"Maharashtra",
... country:"India"}
... })
crud> db.operate.insertMany([{ enroll:
"1013", name: "Usha", college: "VCET",
course: { courseName: "COMP", duration:
"4 years" }, address: { city: "mumbai",
state: "Maharashtra", country: "India" }} ,{
enroll: "1014", name: "Jayesh", college:
"VCET", course: { courseName: "COMP",
duration: "4 years" }, address: { city:
"mumbai", state: "Maharashtra", country:
"India" } }])
crud> db.operate.find().pretty()
crud> db.operate.find().limit(2)
crud> db.operate.find()
crud>
db.operate.updateOne({name:"bhakti"},{$
set:{college:"Vidyavardhinis college of
Engineering"}})
crud> db.operate.find().limit(1)
crud> db.operate.find({name:"Jayesh"})
crud>
db.operate.updateMany({college:"VCET"},
{$set:{courseName:"Computer"}})
crud>
db.operate.find({},{name:1,courseName:1
})
crud> db.operate.find().count()
crud>
db.operate.find({name:"bhakti"}).count()
crud> db.operate.find().limit(2).count()
crud> db.operate.find().sort({name:1}) //
ascending order
crud> db.operate.find().sort({name:-1}) //
descending order
crud>
db.operate.find().sort({name:1}).limit(2)
crud>
db.operate.find({college:{$all:["VCET"]}})
crud>
db.operate.find({college:{$all:["VCET"]}}).c
ount()