W7 - Working With MongoDB Shell (Me)
W7 - Working With MongoDB Shell (Me)
Perform the following tasks in a MongoDB Shell (make sure the MongoDB server is
running). You need to work out proper MongoDB commands / operations to use (refer to
MongoDB manual) in the MongoDb Shell to implement each task below (reference
solution to this part of exercise will be published on Blackboard in the same folder).
title : Avatar
1
// Perform Query / find Documents on the ‘movies’ collection
get all documents
get all documents with `writer` set to “Quentin Tarantino”
get all documents where `actors` include “Brad Pitt”
get all documents with `franchise` set to “The Hobbit”
get all movies released in the 90s
get all movies released before the year 2000 or after 2010
add a synopsis to “The Hobbit: The Desolation of Smaug” : “The dwarves, along
with Bilbo Baggins and Gandalf the Grey, continue their quest to reclaim
Erebor, their homeland, from Smaug. Bilbo Baggins is in possession of a
mysterious and magical ring.”
username : GoodGuyGreg
first_name : “Good Guy”
last_name : “Greg”
username : ScumbagSteve
full_name :
first : “Scumbag”
last : “Steve”
username : GoodGuyGreg
title : Passes out at party
body : Wakes up early and cleans house
username : GoodGuyGreg
title : Steals your identity
body : Raises your credit score
2
username : GoodGuyGreg
title : Reports a bug in your code
body : Sends you a Pull Request
username : ScumbagSteve
title : Borrows something
body : Sells it
username : ScumbagSteve
title : Borrows everything
body : The end
username : ScumbagSteve
title : Forks your repo on github
body : Sets to private
username : GoodGuyGreg
comment : Hope you got a good deal!
post : [post_obj_id]
username : GoodGuyGreg
comment : What's mine is yours!
post : [post_obj_id]
username : GoodGuyGreg
comment : Don't violate the licensing agreement!
post : [post_obj_id]
where [post_obj_id] is the ObjectId of the `posts` document: “Forks your repo
on github
username : ScumbagSteve
comment : It still isn't clean
post : [post_obj_id]
username : ScumbagSteve
comment : Denied your PR cause I found a hack
post : [post_obj_id]
3
find all comments that was authored by “GoodGuyGreg”
find all comments that was authored by “ScumbagSteve”
find all comments belonging to the post “Reports a bug in your code”