0
0
MongoDBquery~10 mins

Why schema design matters in MongoDB - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to insert a document into the 'users' collection.

MongoDB
db.users.insertOne({ name: "Alice", age: [1] })
Drag options to blanks, or click blank then click option'
A"25"
B25
Cage
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes makes them strings.
Using undefined variables instead of values.
2fill in blank
medium

Complete the code to find all documents where the age is greater than 30.

MongoDB
db.users.find({ age: { [1]: 30 } })
Drag options to blanks, or click blank then click option'
A$gt
B$eq
C$lt
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means 'less than'.
Using $eq which means 'equal to'.
3fill in blank
hard

Fix the error in the update command to set the user's city to 'Paris'.

MongoDB
db.users.updateOne({ name: "Bob" }, { [1]: { city: "Paris" } })
Drag options to blanks, or click blank then click option'
Aupdate
Bset
C$update
D$set
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the dollar sign.
Using incorrect operator names.
4fill in blank
hard

Fill both blanks to create a schema design that embeds an address inside a user document.

MongoDB
db.users.insertOne({ name: "Eve", address: { [1]: "123 Main St", [2]: "NY" } })
Drag options to blanks, or click blank then click option'
Astreet
Bcity
Cage
Dcountry
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated fields like age or country here.
Mixing up field names.
5fill in blank
hard

Fill all three blanks to write a query that finds users older than 20 living in 'London'.

MongoDB
db.users.find({ [1]: { [2]: 20 }, address: { [3]: "London" } })
Drag options to blanks, or click blank then click option'
Aage
B$gt
Ccity
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names.
Using wrong operators.