In Problem Set 5 and in lab, you will write queries for a MongoDB version of our movie database – one that uses the data model outlined in lecture.
Create a subfolder called ps5
within your
cs460
folder, and put all of the files for this assignment in that
folder.
Click on each of the following links, and save the files in
your ps5
folder:
If the browser doesn’t allow you to choose where to download the files, right-click each link and use Save link as... or the equivalent option.
Follow the appropriate set of instructions to get everything installed and properly configured:
Make sure that you have downloaded the files listed above and installed and configured the software.
Launch MongoDB Compass as needed and click on the Connect
button to connect to the localhost
MongoDB deployment.
Click on the Databases tab, and then click Create database.
In the window that pops up, enter the following:
imdb
movies
and click Create Database.
Choose the imdb
database from the list of databases. You should
see an empty collection called movies
.
After choosing the imdb
database from the list of databases,
click Create collection and create a new collection with the
name people
.
After choosing the imdb
database from the list of databases,
click Create collection and create a new collection with the
name oscars
.
To add documents to the movies
collection:
In MongoDB Compass, select the collection from the list of
collections for imdb
.
Scroll down as needed to find the Import Data button and click it (NOT the Add Data one).
If needed, click Select a file.... (If you already see a pop-up window, this step isn’t needed.)
Choose the JSON file for the collection that you downloaded
above (e.g., for movies
, the file is called movies.json
).
Click Import. If needed, click DONE.
You should see that the collection now includes the documents that were found in the JSON file.
Repeat step 8 to add documents to the oscars
and
people
collections.
Once you have everything installed and configured, you can perform queries by taking the following steps:
Launch MongoDB Compass.
Click the Connect button to connect to the MongoDB server that
should be running on localhost
.
Click on the MONGOSH
bar at the bottom of the window for MongoDB
Compass. Doing so should expand a pane for the MongoDB shell, and
should see the following command prompt:
test>
Enter the following command from the shell prompt:
use imdb
Note: You may need to hit the Enter/Return key twice in order for the command to be accepted. Once it is, the shell’s prompt should be changed to the following:
imdb>
Enter the appropriate method call for your query.
Note: You can allow your query to span multiple lines if you use Shift-Return or Shift-Enter at the end of a given line.
You should automatically see up to 20 result documents. If there are more than 20 results, you can enter the following command to continue iterating through them:
it
Last updated on November 25, 2024.