Question

For all questions, provide appropriate MongoDB statements. Question 1 (1 point) Create a collection called ‘games’....

For all questions, provide appropriate MongoDB statements.

Question 1 (1 point) Create a collection called ‘games’. We’re going to put some games in it.

Question 2. (2 points) Add 5 games to the database. Give each document the following properties: name, genre, rating (out of 100).

Question 6. (6 points) Update your two favourite games to have two achievements called ‘Game Master’ and ‘Speed Demon’, each under a single key.

Question 7. (2 points) Write a query that returns all the games that have both the ‘Game Maser’ and the ‘Speed Demon’ achievements.

Question 8. (3 points) Write a query that returns only games that have achievements. Not all of your games should have achievements, obviously.

The last 3 are the ones I'm confused by.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1)

db.createCollection("games")

Screenshot:

Question 2)

db.games.insert([{"name":"name1","genre":"genre1","rating":"75"},
{"name":"name2","genre":"genre2","rating":"50"},
{"name":"name3","genre":"genre3","rating":"65"},
{"name":"name4","genre":"genre4","rating":"90"},
{"name":"name5","genre":"genre5","rating":"100"}])

Screenshot:

Question 6)

See that we have to use the object ids that re generated.

These ids change dynamically.

So use the id that is generated while executing the query.

db.games.update({"_id" : ObjectId("5dfb0de3ac1b220c65afffff")},{$set:{"achievements":["Game Master","Speed Demon"]}})
db.games.update({"_id" : ObjectId("5dfb0de3ac1b220c65affffe")},{$set:{"achievements":["Game Master","Speed Demon"]}})

Screenshot:

Question 7)

db.games.find({"achievements":["Game Master","Speed Demon"]})

Screenshot:

Question 8)

db.games.find({achievements:{$exists:true}})

Screenshot:

Add a comment
Know the answer?
Add Answer to:
For all questions, provide appropriate MongoDB statements. Question 1 (1 point) Create a collection called ‘games’....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python question Question 1 Write a Python program to play two games. The program should be...

    python question Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play each game. Call the file containing your program fun games.py. Your program should include the following functions: • function guess The Number which implements the number guessing game. This game is played against the computer and outputs the result of the game (win/lose) as well as number of guesses the user made to during the...

  • Question 2 : Virus Wars A popular subgenre of strategy game is the so-called Virus War...

    Question 2 : Virus Wars A popular subgenre of strategy game is the so-called Virus War format, where the player is shown a field of cells, each with a virus count, and may attack other cells within a certain range. We are going to write some classes in Python to implement a simple Virus Wars game. 2a) The position class (9 points) Everything within this game is going to require a position, so it makes sense to define it up...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT