Complete the code to set the field "age" to 30 in the update operation.
db.users.updateOne({name: "Alice"}, { $set: { age: [1] } })The $set operator updates the value of the specified field. Here, we set age to 30.
Complete the code to set the "status" field to "active" for all matching documents.
db.users.updateMany({ subscribed: true }, { $set: { status: [1] } })The $set operator updates the status field to the string "active" for all users who are subscribed.
Fix the error in the update command to correctly set the "score" field to 100.
db.players.updateOne({ name: "Bob" }, { $set: [1] })The $set operator requires an object with field-value pairs. So, { score: 100 } is correct.
Fill both blanks to set the "level" field to 5 and "active" field to true in one update.
db.accounts.updateOne({ user: "Eve" }, { $set: { [1]: [2], active: true } })To set multiple fields, you list them inside the $set object. Here, the first blank is the field name level, and the second blank is its value 5.
Fill all three blanks to set "score" to 90, "level" to 3, and "active" to false in one update.
db.players.updateOne({ id: 123 }, { $set: { [1]: [2], [3]: 3, active: false } })The $set operator updates multiple fields by listing them inside the object. Here, score is set to 90, level is set to 3, and active is set to false.