0
0
MongoDBquery~10 mins

$unset operator for removing 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 remove the field 'age' from all documents.

MongoDB
db.collection.updateMany({}, [1])
Drag options to blanks, or click blank then click option'
A{ $set: { age: null } }
B{ $remove: { age: 1 } }
C{ $unset: { age: "" } }
D{ $delete: { age: true } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set to null instead of $unset to remove the field.
Using non-existent operators like $remove or $delete.
2fill in blank
medium

Complete the code to remove the 'address' field from documents where 'status' is 'inactive'.

MongoDB
db.collection.updateMany({ status: "inactive" }, [1])
Drag options to blanks, or click blank then click option'
A{ $remove: { address: 1 } }
B{ $unset: { status: "" } }
C{ $set: { address: null } }
D{ $unset: { address: "" } }
Attempts:
3 left
💡 Hint
Common Mistakes
Removing the wrong field.
Using $set instead of $unset.
3fill in blank
hard

Fix the error in the code to correctly remove the 'phone' field from all documents.

MongoDB
db.collection.updateMany({}, { $unset: { phone: [1] } })
Drag options to blanks, or click blank then click option'
A""
Bnull
Ctrue
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using null or true instead of empty string.
Using numeric values like 1 which do not work with $unset.
4fill in blank
hard

Fill both blanks to remove 'email' and 'username' fields from documents where 'active' is false.

MongoDB
db.collection.updateMany({ active: false }, { $unset: { [1]: "", [2]: "" } })
Drag options to blanks, or click blank then click option'
Aemail
Busername
Cactive
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Removing wrong fields like 'active' or 'password'.
Not using empty strings as values.
5fill in blank
hard

Fill all three blanks to remove 'city', 'state', and 'zip' fields from documents where 'country' is 'USA'.

MongoDB
db.collection.updateMany({ country: "USA" }, { $unset: { [1]: "", [2]: "", [3]: "" } })
Drag options to blanks, or click blank then click option'
Acity
Bstate
Czip
Dcountry
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'country' in the fields to remove.
Using non-empty values for $unset fields.