0% found this document useful (0 votes)
10 views4 pages

Mongo Queries 4

The document outlines a series of CRUD operations performed on a MongoDB collection named 'operate'. It includes creating a collection, inserting single and multiple documents, updating specific fields, and querying the data with various filters and sorting options. The operations demonstrate basic database management tasks such as counting documents and retrieving specific fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Mongo Queries 4

The document outlines a series of CRUD operations performed on a MongoDB collection named 'operate'. It includes creating a collection, inserting single and multiple documents, updating specific fields, and querying the data with various filters and sorting options. The operations demonstrate basic database management tasks such as counting documents and retrieving specific fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

test> use crud

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()

You might also like