CS377: Database Design - Create, Read, Update, and Delete (CRUD) with NoSQL

Activity Goals

The goals of this activity are:
  1. To explore the core operations on an unstructured data store: create, update, read, and delete (CRUD)
  2. To be able to implement each of the CRUD operations on a NoSQL database in Python

Supplemental Reading

Feel free to visit these resources for supplemental background reading material.

The Activity


Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity on the Class Activity Questions discussion board. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.

Model 1: Create


  1. Investigate how to create an index in a MongoDB collection using PyMongo.
  2. What kind of data do you think is best suited for a relational database, and what kind might be better suited for this non-relational approach? As a group, write down three examples of each. Let's compare with the class and see who has the most unique ideas!

Model 2: Read


  1. Modify the above program to insert records into a datastore and query them, iterating over the results.
  2. Which statements search for items according to their value?
  3. How is the sorted cursor sorted?
  4. Investigate how to search for records that contain a key called val3 in your collection. Hint: consider the $exists clause.
  5. By default, multiple items in a find are combined using a boolean AND operation. Investigate how to search by combining search terms with an OR. Hint: Consider the $or clause.

Embedded Code Environment

You can try out some code examples in this embedded development environment! To share this with someone else, first have one member of your group make a small change to the file, then click "Open in Repl.it". Log into your Repl.it account (or create one if needed), and click the "Share" button at the top right. Note that some embedded Repl.it projects have multiple source files; you can see those by clicking the file icon on the left navigation bar of the embedded code frame. Share the link that opens up with your group members. Remember only to do this for partner/group activities!

Model 3: Update


  1. What do you think $set and $unset do?
  2. What would the update without the multi modifier do?
  3. What does $push and $rename do?
  4. What does the findAndModify statement do in this example?
  5. What do you think would happen if the query parameter is set to {} in the find and update statements above?

Model 4: Delete


  1. What is an alternative to removing items from a datastore so that you never actually delete anything, while omitting "removed" records from your queries?
  2. Do you think the query parameter works with remove? Try it out, and remove all items from the collection whose val1 value is greater than 42!

Model 5: Putting it All Together with Examples


Submit your answers to the questions using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section.