Assignment On Mongo DB Practicle
Assignment On Mongo DB Practicle
Assignment On Mongo DB Practicle
REGNO: SCT213-C002-0046/2021
MONGODB Practical Assignment - Send before COB , 22ND March 2024
1. Create a mongodb database with three collections:
a. Student, Course and Examinations.
school> db.student.insertOne({name:"elvis",age:21,regno:"SCT213C0020030\2021"})
{
acknowledged: true,
insertedId: ObjectId('65fd8034e4d1e6fcc570eb6a')
}
school> db.course.insertOne({coursename:"law"})
{
acknowledged: true,
insertedId: ObjectId('65fd80fbe4d1e6fcc570eb6c')
}
school> db.examination.insertOne({examname:"calculus"})
{
acknowledged: true,
insertedId: ObjectId('65fd812ae4d1e6fcc570eb6d')
}
II. code to insert multiple values.
school>
db.student.insertMany([{name:"elvis",age:21,regno:"SCT213C0020030\2021"},{name:"james",
age:40,regno:"sct2136724"}])
{
acknowledged: true,
insertedIds: {
'0': ObjectId('65fd8259e4d1e6fcc570eb6e'),
'1': ObjectId('65fd8259e4d1e6fcc570eb6f')
}
}
school> db.course.insertMany([{coursename:"data science"},{coursename:"law"}])
{
acknowledged: true,
insertedIds: {
'0': ObjectId('65fd82c2e4d1e6fcc570eb70'),
'1': ObjectId('65fd82c2e4d1e6fcc570eb71')
}
}
school> db.examination.insertMany([{examname:"probability"},{examname:"theory of
estmation"}])
{
acknowledged: true,
insertedIds: {
'0': ObjectId('65fd8312e4d1e6fcc570eb72'),
'1': ObjectId('65fd8312e4d1e6fcc570eb73')
}
}
school> db.student.drop()
trueknowledged: true,
school> db.school.drop()
true'0': ObjectId('65fd82c2e4d1e6fcc570eb70'),
school> show dbs
Mongo1 192.00 KiB
admin 40.00 KiB
config 108.00 KiBtion.insertMany([{examname:"probability"},{examname:"theory of
estmation"}])
local 108.00 KiB
school 144.00 KiBue,
school> db.school.drop()
school> show dbs
school> db.dropDatabase()
{ok: 1, dropped: 'school' }
4.Write a code to update the values in your collection.
school>
db.student.updateMany({name:"elvis",age:40},{$set:{name:"elviwafuls",age:30}})
{
acknowledged: true,
insertedId: null,
matchedCount: 0,
modifiedCount: 0,
upsertedCount: 0
}
school> db.student.find()
[
{
_id: ObjectId('65fd89a050a84a939f7c3df1'),
name: 'elvis',
age: 21,
regno: 'SCT213C0020030\x821'
},
{
_id: ObjectId('65fd89a050a84a939f7c3df2'),
name: 'james',
age: 40,
regno: 'sct2136724'
}
]
school>