FIT3176 W4 Lab 03 Activity Sheet 1 MongoDB CRUD
FIT3176 W4 Lab 03 Activity Sheet 1 MongoDB CRUD
More details can be found on Moodle > Unit Information > Software Installation Guides
3
CREATE
db.students.insertOne({
"_id": 1001,
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "123 Monash Drive",
"suburb": "Clayton",
"state": "VIC",
"postcode": 3168
},
"gender": "male",
"course": "BITS",
"year": 2019,
"offCampus": false,
"emailAddress": [
"[email protected]",
"[email protected]"
]
})
db.students.insertOne({
"_id": 1002,
"firstName": "Mary",
"lastName": "Citizen",
"address": {
"streetAddress": "900 Dandenong Road",
"suburb": "Caulfield East",
"state": "VIC",
"postcode": 3145
},
"gender": "female",
"course": "BSE",
"year": 2018,
4
"offCampus": true,
"emailAddress": "[email protected]"
})
db.students.insertOne({
"_id": 1003,
"firstName": "Fred",
"lastName": "Bloggs",
"address": {
"streetAddress": "90 Wellington Road",
"suburb": "Clayton",
"state": "VIC",
"postcode": 3168
},
"gender": "male",
"course": [
"BITS",
"BBIS"
],
"year": 2017,
"offCampus": false,
"emailAddress": "[email protected]"
})
db.students.insertOne({
"_id": 1004,
"firstName": "Nick",
"lastName": "Nice",
"address": {
"streetAddress": "3 Robinson Avenue",
"suburb": "Kew",
"state": "VIC",
"postcode": 3080
},
"gender": "male",
"course": "BCS",
"year": 2018,
"offCampus": false,
"emailAddress": "[email protected]"
})
db.students.insertOne({
"_id": 1005,
"firstName": "Wendy",
"lastName": "Wheat",
"address": {
"streetAddress": "6 Algorithm Street",
"suburb": "Malvern",
"state": "VIC",
"postcode": 3144
},
"gender": "female",
"course": "GDS",
"year": 2019,
"offCampus": true,
"emailAddress": "[email protected]"
})
5
READ
1. List all students in the students collection.
10. Count the number of students who are doing BBIS. (Hint: count())
11. Count the number of students who are enrolled in between 2018 to 2019.
12. Find 3 students who are enrolled before 2019 and are doing either BITS or BSE.
13. Sort the student list based on their year enrolled in descending order, and display the name
of the top 3 students.
14. Show the students who are not doing BITS. Display only the names of those students and
sort their names in ascending order.
15. Find the students who are doing a double degree in BITS and BBIS.
UPDATE
1. Assuming Mary Citizen changes her course from BSE to BCS, update the collection to
reflect this change.
3. If you stored the email address for Nick Nice in a string, change it to an array and add a new
email address: [email protected].
4. Add another email address for Nick Nice: [email protected]. (Hint: $push)
5. Find students who are doing the BITS course and add these units:
● Unit Code: FIT3176, Unit Name: Advanced Database Design
● Unit Code: FIT2094, Unit Name: Databases
6
6. Remove the birthday field that we entered for Wendy Wheat. (Hint: $unset)
DELETE
The End