CS-340 2-1 Assignment:CRUD in MongoDB
Overview
To understand and make use of any database system, you must learn various techniques associated with the fundamental operations of create, read, update, and delete (CRUD). For this assignment, you will begin by creating databases of document collections and performing basic reading or querying operations to retrieve specific documents from the database system. You will also gain practice updating documents and subdocuments, and removing documents from a database. You will use the mongo shell and mongoimport commands to complete this assignment.
Note: Since this is the only assignment for Module Two, it is longer than a typical assignment. Be sure to begin working on this early in the week.
Prompt
After completing the textbook reading and reviewing the mongoimport tool documentation in the module resources, complete the following tasks using the mongo shell in Apporto.
- The data set for this assignment, city_inspections.json, has already been loaded into the Apporto environment for you. Using the mongoimport tool, load the database “city” with documents found in the city_inspections.json file into the “inspections” collection. Complete this by typing the following commands in the Linux terminal to perform the import in the right directory:
cd /usr/local/datasets/ #change into the Apporto directory with the data sets mongoimport --db city --collection inspections ./city_inspections.json #mongo import utility
TIP: In any Linux systems, commands must be exact and use proper syntax and case sensitivity.
- Verify your load by switching to the “city” database and issuing the following queries in the mongo shell:
- db.inspections.find({"id" : "10021-2015-ENFO"})
- db.inspections.find({"result":"Out of Business"},{"business_name":1}).limit(10)
- Using the appropriate commands in the mongo shell, insert a document to the database named “city” within the collection named “inspections.” Use the following key-value pairs as data for your document.
Be sure the address is inserted as a sub-document, and use the JavaScript function Date() for “Today’s date.” Verify your database creation and insertion using the findOne() function in the mongo shell. Provide a screenshot as evidence.Key Value id “20032-2020-ACME” certificate_number 9998888 business_name “ACME Explosives” date Today’s date result “Business Padlocked” sector “Explosive Retail Dealer-999” address number -> 1721 street -> Boom Road city -> BRONX zip -> 10463
- Answer the following questions using MongoDB queries.
- What is the distinct list of inspection “sector” in the current inspections collection? How many are in the list? Do not count by hand.
- What is the difference in the date data type for the business named “AUSTIN 2012” versus your business document insertion of “Acme Explosives”?
- How many businesses have a “Violation Issued”? (See Value column above.)
- Using the appropriate command in the mongo shell, update the document with the ID “20032-2020-ACME” in the collection “inspections” in the database “city” with the information below.
Verify your database update using the appropriate find() function in the mongo shell. Provide a screenshot as evidence.Key Value business_name "New ACME Flowers" result "Business Re-opened" comments "Flowers after the explosion"
- Using the database “city” with documents found in the “inspections” collection, perform the tasks listed below. Verify by providing screenshots of the results as evidence.
- Update all the documents that contain the key-value pair "city":"ROSEDALE" in the address subdocument by changing the zip code in the address subdocument to "76114".
- Remove the first document with the key-value pair "result":"Violation Issued."
Guidelines for Submission
Submit a Word document containing all of your screenshots. Use a screenshot tool, such as the Snipping Tool, for your screenshots and be sure to enlarge the images in the Word document before submitting. This will help make sure that your screenshots are an appropriate size for your instructor to be able to read them. Refer to this Use Snipping Tool to Capture Screenshots guide for help with taking screenshots.
Module Two Assignment Rubric
Criteria Proficient (100%) Needs Improvement (70%) Not Evident (0%) Value Database Creation Creates database using mongoimport tool and verifies load with find() commands Shows progress toward proficiency, but with errors or omissions; areas for improvement may include errors in using mongoimport tool or failure to verify load Does not attempt criterion 30 Data Insertion Inserts document correctly and validates data using findOne() Shows progress toward proficiency, but with errors or omissions; areas for improvement may include incorrect document insertion or failing to validate data Does not attempt criterion 10 MongoDB Queries Performs queries on database to retrieve requested information that is accurate Shows progress toward proficiency, but with errors or omissions; areas for improvement may include not performing queries on database to retrieve accurate information Does not attempt criterion 15 Update Document Updates correct document successfully Shows progress toward proficiency, but with errors or omissions; areas for improvement may include updating correct document with errors Does not attempt criterion 15 Update Subdocument Updates correct subdocument successfully Shows progress toward proficiency, but with errors or omissions; areas for improvement may include updating correct subdocument with errors Does not attempt criterion 15 Remove Document Removes correct document successfully Shows progress toward proficiency, but with errors or omissions; areas for improvement may include removing correct document with errors Does not attempt criterion 15 Total: 100%