0
0
MongoDBquery~10 mins

$rename operator for field names 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 rename the field 'oldName' to 'newName' in a MongoDB update operation.

MongoDB
db.collection.updateOne({}, { $rename: { [1]: 'newName' } })
Drag options to blanks, or click blank then click option'
A'newName'
B'oldName'
C'old_name'
D'nameOld'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the new field name as the key instead of the old field name.
Forgetting to put the field name in quotes.
2fill in blank
medium

Complete the code to rename the field 'username' to 'user_name' in all documents.

MongoDB
db.collection.updateMany({}, { $rename: { [1]: 'user_name' } })
Drag options to blanks, or click blank then click option'
A'username'
B'user_name'
C'userName'
D'user-name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the new field name as the key.
Changing the case of the field name incorrectly.
3fill in blank
hard

Fix the error in the code to rename 'address' to 'location' in one document.

MongoDB
db.collection.updateOne({}, { $rename: { address: [1] } })
Drag options to blanks, or click blank then click option'
Alocation
B'address'
Clocation'
D'location'
Attempts:
3 left
💡 Hint
Common Mistakes
Not putting the new field name in quotes.
Using unbalanced quotes.
4fill in blank
hard

Fill both blanks to rename 'phone' to 'contactNumber' in all documents.

MongoDB
db.collection.updateMany({}, { $rename: { [1]: [2] } })
Drag options to blanks, or click blank then click option'
A'phone'
B'contactNumber'
C'phoneNumber'
D'contact_number'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping old and new field names.
Forgetting quotes around field names.
5fill in blank
hard

Fill all three blanks to rename 'email' to 'contactEmail' and 'dob' to 'dateOfBirth' in one update operation.

MongoDB
db.collection.updateMany({}, { $rename: { [1]: [2], [3]: 'dateOfBirth' } })
Drag options to blanks, or click blank then click option'
A'email'
B'contactEmail'
C'dob'
D'dateOfBirth'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up old and new field names.
Not quoting field names properly.