0
0
MongoDBquery~10 mins

$set operator for setting fields in MongoDB - Interactive Code Practice

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

Complete the code to set the field "age" to 30 in the update operation.

MongoDB
db.users.updateOne({name: "Alice"}, { $set: { age: [1] } })
Drag options to blanks, or click blank then click option'
A25
B30
C35
D40
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for the age value.
Forgetting to use the $set operator.
2fill in blank
medium

Complete the code to set the "status" field to "active" for all matching documents.

MongoDB
db.users.updateMany({ subscribed: true }, { $set: { status: [1] } })
Drag options to blanks, or click blank then click option'
Afalse
Btrue
C"inactive"
D"active"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a boolean value instead of a string.
Omitting the quotes around the string value.
3fill in blank
hard

Fix the error in the update command to correctly set the "score" field to 100.

MongoDB
db.players.updateOne({ name: "Bob" }, { $set: [1] })
Drag options to blanks, or click blank then click option'
A{ score: 100 }
B[ score: 100 ]
Cscore: 100
D"score: 100"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using curly braces around the field and value.
Using square brackets or quotes incorrectly.
4fill in blank
hard

Fill both blanks to set the "level" field to 5 and "active" field to true in one update.

MongoDB
db.accounts.updateOne({ user: "Eve" }, { $set: { [1]: [2], active: true } })
Drag options to blanks, or click blank then click option'
Alevel
B5
Cactive
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the value before the field name.
Using quotes incorrectly around numbers.
5fill in blank
hard

Fill all three blanks to set "score" to 90, "level" to 3, and "active" to false in one update.

MongoDB
db.players.updateOne({ id: 123 }, { $set: { [1]: [2], [3]: 3, active: false } })
Drag options to blanks, or click blank then click option'
Ascore
B90
Clevel
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up field names and values.
Forgetting commas between fields.