0
0
MongoDBquery~10 mins

updateMany method 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 update all documents where age is greater than 25.

MongoDB
db.collection.updateMany({ age: { $[1]: 25 } }, { $set: { status: "active" } })
Drag options to blanks, or click blank then click option'
Aeq
Bgt
Clt
Dne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means less than.
Using $eq which means equal to.
2fill in blank
medium

Complete the code to set the field "verified" to true for all users with status "pending".

MongoDB
db.users.updateMany({ status: "[1]" }, { $set: { verified: true } })
Drag options to blanks, or click blank then click option'
Aactive
Bdeleted
Cinactive
Dpending
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'active' which means already approved.
Using 'inactive' which means disabled.
3fill in blank
hard

Fix the error in the updateMany query to increment the "score" field by 10 for all documents.

MongoDB
db.scores.updateMany({}, { $[1]: { score: 10 } })
Drag options to blanks, or click blank then click option'
Ainc
Bpush
Cadd
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set which replaces the field value.
Using $push which is for arrays.
4fill in blank
hard

Fill both blanks to update the "status" to "archived" for documents where "lastLogin" is less than 2020.

MongoDB
db.accounts.updateMany({ lastLogin: { $[1]: 2020 } }, { $[2]: { status: "archived" } })
Drag options to blanks, or click blank then click option'
Alt
Bgt
Cset
Dinc
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $lt for the date comparison.
Using $inc instead of $set for updating a string field.
5fill in blank
hard

Fill all three blanks to increment the "visits" by 1 for users with "role" equal to "member".

MongoDB
db.users.updateMany({ role: "[1]" }, { $[2]: { visits: [3] } })
Drag options to blanks, or click blank then click option'
Amember
Binc
C1
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set instead of $inc for incrementing.
Using a wrong role name.