I need help with this assignment for my Advanced Database Class. Using MongoDB 1
ID: 3827559 • Letter: I
Question
I need help with this assignment for my Advanced Database Class.
Using MongoDB
1. Create a Database with the first part of your KSU email address. (For example, for jdow@students.kennesaw.edu, the database name jdow.)
2. Import zips.json into your Database, and collection zipcode. (provide commands you used and screenshot of the results)
3. Write and Run a Mongo Shell command which is equivalent to "SELECT * FROM zipcode WHERE pop>100000" (provide commands you used and screenshot of the results)
4. Write and Run a Mongo Shell command which is equivalent to "SELECT * FROM zipcode WHERE city=' OIL CITY'" (provide commands you used and screenshot of the results)
5. Write and Run a Mongo Shell command which is equivalent to "UPDATE zipcode SET state='Texas' WHERE state='TX'" (provide commands you used and screenshot of the results)
6. Write and Run a Mongo Shell command which is equivalent to "DELETE FROM zipcode WHERE city LIKE '%TREE%'" (provide commands you used and screenshot of the results)
Explanation / Answer
1. Create a Database (mail-id : myname@abcd.com)
solution : use myname;
2. Import zips.json into your Database, and collection zipcode
solution: mongoimport --db myname --collection zipcode --file zips.json
3. Write and Run a Mongo Shell command which is equivalent to "SELECT * FROM zipcode WHERE pop>100000"
solution: db.zipcode.find({pop:{$gt:100000}});
4. Write and Run a Mongo Shell command which is equivalent to "SELECT * FROM zipcode WHERE city='OIL CITY'"
solution: db.zipcode.find({city:"OIL CITY"});
5. Write and Run a Mongo Shell command which is equivalent to "UPDATE zipcode SET state='Texas' WHERE state='TX'"
solution: db.zipcode.update({'state':'TX'},{$set:{'state':'Texas'}});
6. Write and Run a Mongo Shell command which is equivalent to "DELETE FROM zipcode WHERE city LIKE '%TREE%'"
solution: db.zipcode.remove({'state':/TREE/});