Assi 9
Assi 9
db.createCollection("student")
{ ok: 1 }
---------------------------------------------
db.student.insertOne({
name:"prati",
age:19,
place:"pune",
department:"CE",
gpa: 3.8,
acknowledged: true,
insertedId: ObjectId('6708257f8aecdd95464ab95e')
--------------------------------------------------------------------------------------------
name: "Pratik",
age: 21,
gpa: 3.8,
},
name: "Prathem",
age: 23,
gpa: 3.4,
},
{
name: "Sayali",
age: 22,
gpa: 3.9,
},
name: "Soham",
age: 20,
gpa: 3.6,
},
name: "Sanu",
age: 21,
gpa: 3.7,
])
acknowledged: true,
insertedIds: {
'0': ObjectId('6708b7c77ee56f41e3189116'),
'1': ObjectId('6708b7c77ee56f41e3189117'),
'2': ObjectId('6708b7c77ee56f41e3189118'),
'3': ObjectId('6708b7c77ee56f41e3189119'),
'4': ObjectId('6708b7c77ee56f41e318911a')
}
________________________________________________________________________
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,
gpa: 3.8,
courses: [
'Algorithms',
'Data Structures',
'Databases'
_id: ObjectId('6708b7c77ee56f41e3189116'),
name: 'prati',
age: 20,
gpa: 3.8,
courses: [
'Algorithms',
'Data Structures',
'Databases'
_id: ObjectId('6708b7c77ee56f41e3189117'),
name: 'Prathem',
age: 23,
gpa: 3.4,
courses: [
'Thermodynamics',
'Mechanics',
'Design'
_id: ObjectId('6708b7c77ee56f41e3189118'),
name: 'Sayali',
age: 22,
courses: [
'Operating Systems',
'Machine Learning',
'Cloud Computing'
_id: ObjectId('6708b7c77ee56f41e3189119'),
name: 'Soham',
age: 20,
gpa: 3.6,
courses: [
'Circuits',
'Electronics',
'Control Systems'
_id: ObjectId('6708b7c77ee56f41e318911a'),
name: 'Sanu',
age: 21,
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,
gpa: 3.8,
courses: [
'Algorithms',
'Data Structures',
'Databases'
_id: ObjectId('6708b7c77ee56f41e3189117'),
name: 'Prathem',
age: 23,
gpa: 3.4,
courses: [
'Thermodynamics',
'Mechanics',
'Design'
{
_id: ObjectId('6708b7c77ee56f41e3189118'),
name: 'Sayali',
age: 22,
gpa: 3.9,
courses: [
'Operating Systems',
'Machine Learning',
'Cloud Computing'
_id: ObjectId('6708b7c77ee56f41e3189119'),
name: 'Soham',
age: 20,
gpa: 3.6,
courses: [
'Circuits',
'Electronics',
'Control Systems'
_id: ObjectId('6708b7c77ee56f41e318911a'),
name: 'Sanu',
age: 21,
gpa: 3.7,
courses: [
'Software Engineering',
'Networks',
'AI'
]
}
------------------------------------------------------------------------------------------------------------------------
db.student.updateMany(
},
{ upsert: true }
acknowledged: true,
insertedId: null,
matchedCount: 3,
modifiedCount: 3,
upsertedCount: 0
—-
_id: ObjectId('6708b7c77ee56f41e3189116'),
name: 'Pratik',
age: 21,
gpa: 3.8,
courses: [
'Algorithms',
'Data Structures',
'Databases',
'Distributed Systems'
]
_id: ObjectId('6708b7c77ee56f41e3189118'),
name: 'Sayali',
age: 22,
gpa: 3.9,
courses: [
'Operating Systems',
'Machine Learning',
'Cloud Computing',
'Distributed Systems'
_id: ObjectId('6708b7c77ee56f41e318911a'),
name: 'Sanu',
age: 21,
gpa: 3.7,
courses: [
'Software Engineering',
'Networks',
'AI',
'Distributed Systems'