CSE313: Big Data Analytics – Lab Assignment 3
1
MongoDB
Use MongoDB command line for all the assignments.
- Create a database called class.
- Create a collection called students and Insert few students with their name, address and age
- Find students with a given address. Ex: Find all student whose address is Beijing then update the students address to Suzhou.
- Print all students’ name and address but not age and _id.
- Find all the students age between age 20 to 25.
- Sort the students by the age (low to high) and print first 3 students.
- Update the students collection such a way that same student name can not be inserted twice in two records (i.e. ensure student name is the unique in the collection).
-
Consider a student Jack Ma’s address is an embedded document as shown below:
{
“name”: “Jack Ma”,
“address”: {
“street”: ” 111 Ren’ai Road “,
“city”: “Suzhou”,
“state”: “Jiansu”
}
}
Insert this document into MongoDB. Write a query to search for all students who lives in the city Suzhou and name is Jack Ma. Remember city field is inside address document.