数据库代写 MongoDB

CSE313: Big Data Analytics – Lab Assignment 3

1

MongoDB

Use MongoDB command line for all the assignments.

  1. Create a database called class.
  2. Create a collection called students and Insert few students with their name, address and age
  3. Find students with a given address. Ex: Find all student whose address is Beijing then update the students address to Suzhou.
  4. Print all students’ name and address but not age and _id.
  5. Find all the students age between age 20 to 25.
  6. Sort the students by the age (low to high) and print first 3 students.
  7. 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).
  8. 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.