0% found this document useful (0 votes)
33 views

Assignment On Mongo DB Practicle

note

Uploaded by

khisakipsang
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)
33 views

Assignment On Mongo DB Practicle

note

Uploaded by

khisakipsang
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

NAME : SAMWEL KIPSANG KHISA

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.

test> use school


switched to db school
school> db.createCollection("student")
{ ok: 1 }
school> db.createCollection("course")
{ ok: 1 }
school> db.createCollection("examination")
{ ok: 1 }
2.Have a code to insert one value and another code to insert multiple values.
I. to insert one value

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')
}
}

3.Write code to delete collection and code to delete database

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>

You might also like