0% found this document useful (0 votes)
4 views2 pages

B1

The document outlines the creation and manipulation of a 'students' collection in a MongoDB database. It includes inserting multiple student records, updating a student's age, querying students with scores greater than 7.0, and deleting students based on score and class criteria. The operations demonstrate basic CRUD functionalities in MongoDB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

B1

The document outlines the creation and manipulation of a 'students' collection in a MongoDB database. It includes inserting multiple student records, updating a student's age, querying students with scores greater than 7.0, and deleting students based on score and class criteria. The operations demonstrate basic CRUD functionalities in MongoDB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

B1

school> db.createCollection("students")
{ ok: 1 }
school> db.students.insertMany([
... { name: "Nguyen Van A", age: 20, class: "12A1", scores: 8.5 },
... { name: "Le Thi B", age: 19, class: "12A2", scores: 6.5 },
... { name: "Tran Van C", age: 18, class: "12A1", scores: 7.2 },
... { name: "Pham Thi D", age: 21, class: "12A3", scores: 4.8 },
... { name: "Hoang Van E", age: 22, class: "12A2", scores: 9.1 }
... ])
...
{
acknowledged: true,
insertedIds: {
'0': ObjectId('67e594fdf0e58e6d8eb71240'),
'1': ObjectId('67e594fdf0e58e6d8eb71241'),
'2': ObjectId('67e594fdf0e58e6d8eb71242'),
'3': ObjectId('67e594fdf0e58e6d8eb71243'),
'4': ObjectId('67e594fdf0e58e6d8eb71244')
}
}
school> db.students.find().pretty()
[
{
_id: ObjectId('67e594fdf0e58e6d8eb71240'),
name: 'Nguyen Van A',
age: 20,
class: '12A1',
scores: 8.5
},
{
_id: ObjectId('67e594fdf0e58e6d8eb71241'),
name: 'Le Thi B',
age: 19,
class: '12A2',
scores: 6.5
},
{
_id: ObjectId('67e594fdf0e58e6d8eb71242'),
name: 'Tran Van C',
age: 18,
class: '12A1',
scores: 7.2
},
{
_id: ObjectId('67e594fdf0e58e6d8eb71243'),
name: 'Pham Thi D',
age: 21,
class: '12A3',
scores: 4.8
},
{
_id: ObjectId('67e594fdf0e58e6d8eb71244'),
name: 'Hoang Van E',
age: 22,
class: '12A2',
scores: 9.1
}
]
school> db.students.updateOne({ name: "Nguyen Van A" }, { $set: { age: 21 } })
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 1,
upsertedCount: 0
}
school> db.students.find({ scores: { $gt: 7.0 } }).pretty()
[
{
_id: ObjectId('67e594fdf0e58e6d8eb71240'),
name: 'Nguyen Van A',
age: 21,
class: '12A1',
scores: 8.5
},
{
_id: ObjectId('67e594fdf0e58e6d8eb71242'),
name: 'Tran Van C',
age: 18,
class: '12A1',
scores: 7.2
},
{
_id: ObjectId('67e594fdf0e58e6d8eb71244'),
name: 'Hoang Van E',
age: 22,
class: '12A2',
scores: 9.1
}
]
school> db.students.deleteMany({ scores: { $lt: 5.0 } })
{ acknowledged: true, deletedCount: 1 }
school> db.students.deleteMany({ class: "12A1" })
{ acknowledged: true, deletedCount: 2 }

You might also like