Create a text file (named hw13.js) containing MongoDB commands that
when executed will establish a collection named “patients” in a database named
hw13. You will populate the collection with documents and then query, update,
and delete entries in accordance with the instructions below.
The final script should begin with a command to remove all data from the
patients collection so that each time it is run there is a clean starting
point. The hw13.js file should be executable by the provided
mongoexec script on csci.hsutx.edu.
The patients collection will contain documents that have this general
structure:
{
"firstname": "Fred",
"lastname" : "Smith",
"age": 29,
"history": [
{ "diagnosis": "flu", "treatment": "Tamiflu" },
{ "diagnosis": "inflamed nostrils", "treatment": "nostril de-infamer" }
]
}
- (7 pts) Begin by inserting 8 different patient documents in the database. You
should use at least 1 .insertOne() command and at least one .insertMany()
command. Make sure there are multiple patients (but not all) who have a diagnosis
of “flu”. Make sure some patients and over 30 years of age and some who are less than
30 and some who are over 50).
At least two (but not all) of the patients should have a last name of Smith.
One patient should have a completely missing history key/value pair.
- (2 pts) Once those inserts are working, add a delete command in front of
those inserts so it will clear the collection each time you run your
script.
- (2 pts) Write a find command that will show all info about patients whose last name
is “Smith”.
- (2 pts) Write a find command that will show all info about patients who are over 30
years of age.
- (2 pts) Write a find command that will show all info for all patients
who have ever been diagnosed with the flu.
- (2 pts) Write a find command that will show only last name and age of all patients.
- (3 pts) Write a command that will add a history array for the existing
patient who is missing their history data.
- (3 pts) Write a command that will add a key called “recommendations” with a value
of “colonoscopy” for all patients who are age 50 or older.
- (3 pts) Write a command that will delete all patients who have a last name of "Smith".
A pretty efficient workflow would be for you to have two terminal connections to the csci
server. In one window have a shell command open to the database and in the other work on
editing hw13.js. In the database shell try commands until you get something that
works and then copy that working command into hw13.js. Every so often
use the mongoexec script to run the commands in hw13.js and verify
they are doing what you want.
Upload your script (with .js extension) into canvas. The script should
include commands to execute the queries/functions described above.