0% found this document useful (0 votes)
2 views10 pages

Assi 9

The document outlines various MongoDB operations performed on a 'student' collection, including creating the collection, inserting single and multiple student records, updating a student's age, deleting a record, and adding a new course to students in the Computer Science department. It also shows the results of each operation, including acknowledged responses and modified counts. The final state of the student records is displayed after all operations.

Uploaded by

pratikp3800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Assi 9

The document outlines various MongoDB operations performed on a 'student' collection, including creating the collection, inserting single and multiple student records, updating a student's age, deleting a record, and adding a new course to students in the Computer Science department. It also shows the results of each operation, including acknowledged responses and modified counts. The final state of the student records is displayed after all operations.

Uploaded by

pratikp3800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Insert one record

db.createCollection("student")

{ ok: 1 }

---------------------------------------------
db.student.insertOne({

name:"prati",

age:19,

place:"pune",

department:"CE",

gpa: 3.8,

courses: ["Algorithms", "Data Structures", "Databases"])

acknowledged: true,

insertedId: ObjectId('6708257f8aecdd95464ab95e')

--------------------------------------------------------------------------------------------

insert multiple records


db.student.insertMany([

name: "Pratik",

age: 21,

department: "Computer Science",

gpa: 3.8,

courses: ["Algorithms", "Data Structures", "Databases"]

},

name: "Prathem",

age: 23,

department: "Mechanical Engineering",

gpa: 3.4,

courses: ["Thermodynamics", "Mechanics", "Design"]

},
{

name: "Sayali",

age: 22,

department: "Computer Science",

gpa: 3.9,

courses: ["Operating Systems", "Machine Learning", "Cloud Computing"]

},

name: "Soham",

age: 20,

department: "Electrical Engineering",

gpa: 3.6,

courses: ["Circuits", "Electronics", "Control Systems"]

},

name: "Sanu",

age: 21,

department: "Computer Science",

gpa: 3.7,

courses: ["Software Engineering", "Networks", "AI"]

])

acknowledged: true,

insertedIds: {

'0': ObjectId('6708b7c77ee56f41e3189116'),

'1': ObjectId('6708b7c77ee56f41e3189117'),

'2': ObjectId('6708b7c77ee56f41e3189118'),

'3': ObjectId('6708b7c77ee56f41e3189119'),

'4': ObjectId('6708b7c77ee56f41e318911a')
}

________________________________________________________________________

Q change age of priti to 20

db.student.updateOne(

name:"prati"

},

$set:{age:20}

})

acknowledged: true,

insertedId: null,

matchedCount: 1,

modifiedCount: 1,

upsertedCount: 0

}
---------------------------------------------------------------------------------------------

db.student.find().pretty()

_id: ObjectId('6708b7c77ee56f41e3189116'),

name: 'Pratik',

age: 21,

department: 'Computer Science',

gpa: 3.8,

courses: [

'Algorithms',

'Data Structures',
'Databases'

_id: ObjectId('6708b7c77ee56f41e3189116'),

name: 'prati',

age: 20,

department: 'Computer Science',

gpa: 3.8,

courses: [

'Algorithms',

'Data Structures',

'Databases'

_id: ObjectId('6708b7c77ee56f41e3189117'),

name: 'Prathem',

age: 23,

department: 'Mechanical Engineering',

gpa: 3.4,

courses: [

'Thermodynamics',

'Mechanics',

'Design'

_id: ObjectId('6708b7c77ee56f41e3189118'),

name: 'Sayali',

age: 22,

department: 'Computer Science',


gpa: 3.9,

courses: [

'Operating Systems',

'Machine Learning',

'Cloud Computing'

_id: ObjectId('6708b7c77ee56f41e3189119'),

name: 'Soham',

age: 20,

department: 'Electrical Engineering',

gpa: 3.6,

courses: [

'Circuits',

'Electronics',

'Control Systems'

_id: ObjectId('6708b7c77ee56f41e318911a'),

name: 'Sanu',

age: 21,

department: 'Computer Science',

gpa: 3.7,

courses: [

'Software Engineering',

'Networks',

'AI'

--------------------------------------------------------------------------------
Q delete record of priti
db.student.deleteOne({"name":{$eq:"prati"}})

acknowledged: true,

deletedCount: 1

db.student.find()

_id: ObjectId('6708b7c77ee56f41e3189116'),

name: 'Pratik',

age: 21,

department: 'Computer Science',

gpa: 3.8,

courses: [

'Algorithms',

'Data Structures',

'Databases'

_id: ObjectId('6708b7c77ee56f41e3189117'),

name: 'Prathem',

age: 23,

department: 'Mechanical Engineering',

gpa: 3.4,

courses: [

'Thermodynamics',

'Mechanics',

'Design'

{
_id: ObjectId('6708b7c77ee56f41e3189118'),

name: 'Sayali',

age: 22,

department: 'Computer Science',

gpa: 3.9,

courses: [

'Operating Systems',

'Machine Learning',

'Cloud Computing'

_id: ObjectId('6708b7c77ee56f41e3189119'),

name: 'Soham',

age: 20,

department: 'Electrical Engineering',

gpa: 3.6,

courses: [

'Circuits',

'Electronics',

'Control Systems'

_id: ObjectId('6708b7c77ee56f41e318911a'),

name: 'Sanu',

age: 21,

department: 'Computer Science',

gpa: 3.7,

courses: [

'Software Engineering',

'Networks',

'AI'

]
}

------------------------------------------------------------------------------------------------------------------------

Q add course "Distributed Systems" in department computer science

db.student.updateMany(

{ department: "Computer Science" },

$push: { courses: "Distributed Systems" }

},

{ upsert: true }

acknowledged: true,

insertedId: null,

matchedCount: 3,

modifiedCount: 3,

upsertedCount: 0

—-

db.student.find({department :{$eq:"Computer Science"}})

_id: ObjectId('6708b7c77ee56f41e3189116'),

name: 'Pratik',

age: 21,

department: 'Computer Science',

gpa: 3.8,

courses: [

'Algorithms',

'Data Structures',

'Databases',

'Distributed Systems'
]

_id: ObjectId('6708b7c77ee56f41e3189118'),

name: 'Sayali',

age: 22,

department: 'Computer Science',

gpa: 3.9,

courses: [

'Operating Systems',

'Machine Learning',

'Cloud Computing',

'Distributed Systems'

_id: ObjectId('6708b7c77ee56f41e318911a'),

name: 'Sanu',

age: 21,

department: 'Computer Science',

gpa: 3.7,

courses: [

'Software Engineering',

'Networks',

'AI',

'Distributed Systems'

You might also like