Description
Set Up:
You will use and instance of the MongoDB database that I have set up for you in the Azure cloud. Note, as I am paying for this myself, I will only keep the database available until next Thursday.
To access the database do the following. Note, enter the command manually rather than cutting or pasting them which sometimes picks up non-printing characters.
a) Access the databaseVM via ssh…
ssh –p 22 mdb1@65.52.219.66
b) When prompted for a password use…
Unix79127912
c) Once logged in to the MongoDB VM create a working directory for yourself. The name of the directory should be your IIT id (mine is A20155104): mkdir
d) This will be your working directory into which you will place your command files
e) Open a second terminal window and ssh into the VM again as above.
f) Change to the working directory you created previously: cd
g) Start the MongoDB shell by entering the following. Note that the “–“ is actually two dashes (not just one) one after another…
mongo admin –username root –password Unix79127912
h) Create a database and give it your IIT id. To do this just enter the following at the mongodb shell:use . This will set the shell variable ‘db’ to this new database.
i) Load the collection unicorns with data by executing the script ex2.js which is located in the jrosen subdirectory as follows:
load(“/home/mdb1/jrosen/ex3.js”)
j) Confirm this has all worked by executing the following command
db.unicorns.find();
Look at the content of the script file to see how each unicorn is described.
Exercise 1) (2 points)
Write a command that finds all unicorns having weight less than 500 pounds. Include the code you executed and some sample output as the result of this exercise.
Exercise 2) (2 points)
Write a command that finds all unicorns who love apples. Hint, search for “apple”. Include the code you executed and some sample output as the result of this exercise.
Exercise 3) (2 points)
Write a command that adds a unicorn with the following attributes to the collection. Note dob means “Date of Birth.”
Attribute Value(s)
name Malini
dob 11/03/2008
loves Pears and grapes
weight 450
gender F
vampires 23
horns 1
Include the code you executed to insert this unicorn into the collection along with the output of a find command showing it is in the collection.
Exercise 4) (4 points)
Write a command that updates the above record to add apricots to the list of things Malini loves.Include the code you executed and some sample output showing the addition.
Exercise 5) (2 points)
Write a command that deletes all unicorns with weight more than 600 pounds. Include the code you executed and some sample output as the result of this exercise.