ITP 249
Part 1: MongoDB
1. Installing STUDIO 3T a Mongo Client on your computer.
- Go to https://studio3t.com/download/
- Download and install Studio 3T Client on your computer. Use the version corresponding to your OS. i.e. Windows/MacOS/Linux
-
For
Windows only:
- Go to https://www.mongodb.com/download-center?jmp=homepage#community
- Go to the Products -> Software -> MongoDB Server, then click Download MongoDB
- Download and unzip Mongo Community Server that corresponds to your Windows version
*make sure to choose Package: ZIP
- Launch Studio 3T, accept terms and finish
-
You
will now connect to the ITP MongoDB server
- Click on Connect
- Click on New Connection
- Enter a name for this connection: ITP 249 MongoDB
-
Under
Server tab
- Connection Type: Standard/Direct Connection
-
Members:
- Remove the Localhost
- Add a new Member with Server: itpmongodb.usc.edu Port: 27017
-
Under
Authentication tab
- Authentication Mode: Basic
- Username: your USC email username (e.g. kale)
- Password: your 10-digit USC student ID (e.g. 1234567890)
- Authentication DB: your USC email username (e.g. kale)
- Click on Test Connection. Make sure there is no errors.
- Save
- Choose the connection you just made. Click Connect.
- On the left panel you will see your database.
-
For
Windows only: Now you will
configure the IntelliShell where you can issue MongoDB commands.
- Go to Menu – Edit – Preferences – Click on IntelliShell
- Select Use the following ‘mongo’ executable
- Browse to the bin folder of the Mongo Community Server you downloaded and unzipped earlier and find the mongo.exe file, e.g. C:Program FilesMongoDBServer3.4binmongo.exe
- Click OK
- You are now ready to work with your Mongo Database
2. Importing a Collection
- In MongoDB, a Database consists of Collections. Collections consist of Documents. Documents contain data. The Schema of the database does not need to be defined.
- You can create Collections and Documents by inserting the data manually or by importing them.
- You will use the Yelp users dataset for this homework.
- From Blackboard, download the Zip file Yelp users.zip
- Unzip it to get the JSON file Yelp users.json
- JSON stands for JavaScript Object Notation.
- JSON is a syntax for storing and exchanging data. It uses an attribute and a value pair to represent data. E.g. the following is a JSON representation of a Yelp user:
“_id” : ObjectId(“58f3f82fe332b12848c97815”),
“user_id” : “PM9KEkLNoH9p4LeR49N4WQ”,
“name” : “Natalie”,
“review_count” : NumberInt(18),
“yelping_since” : “2013-04-25”,
“friends” : [
“None”
],
“useful” : NumberInt(0),
“funny” : NumberInt(0),
“cool” : NumberInt(0),
“fans” : NumberInt(1),
“elite” : [
“None”
],
“average_stars” : 3.47,
“compliment_hot” : NumberInt(0),
“compliment_more” : NumberInt(0),
“compliment_profile” : NumberInt(0),
“compliment_cute” : NumberInt(0),
“compliment_list” : NumberInt(0),
“compliment_note” : NumberInt(0),
“compliment_plain” : NumberInt(1),
“compliment_cool” : NumberInt(0),
“compliment_funny” : NumberInt(0),
“compliment_writer” : NumberInt(0),
“compliment_photos” : NumberInt(0),
“type” : “user”
- Explore this user or any other user on Yelp to familiarize yourself with the publicly available user data. https://www.yelp.com/user_details?userid=KUCivrQtY-iCWzb_K7oSOg
- To import the JSON dataset, expand your database name. Right click Collections and then choose Import Collections.
- Next
- Click on +
- Browse to the downloaded Yelp users.json file
- Check the box “Validate JSON before import”
- Execute
- After a short while, the JSON file is imported as a collection
- Right click the Yelp users collection and Open Collection
- You should now see the user data. You should explore the Result panel of your dataset to see how the user data map from the yelp website to the JSON dataset
- You can change the view of the data from Tree to Table to JSON (using the dropdown at the upper right of the Result panel
- Now you are ready to query this NoSQL database!
- Write query in the IntelliShell. Refer to this website for the query examples http://www.w3resource.com/mongodb-exercises/
- After writing the query, click on Run to see the results
YELP USERS QUERIES
Answer the following questions (Please include both screenshots and query codes):
- List the user names in decreasing order of average_stars.
- List the user name and review count of the user with the highest number of reviews
- Which user has yelped for the longest time?
- List the name of the user (and the number of friends) with the most friends
(hint: use $size to get the number of friends)
- Which user (name) has the most number of overall compliments?
(hint: use $add to add up all of the compliments to determine who has the most)
Fill out the Project Answer Sheet this part posted on Blackboard. Submit to Blackboard.
The post ITP 249 Part 1: MongoDB appeared first on My Assignment Online.