0
0
MongoDBquery~10 mins

$replaceRoot for restructuring 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 replace the root document with the "details" field.

MongoDB
db.collection.aggregate([{ $replaceRoot: { newRoot: [1] } }])
Drag options to blanks, or click blank then click option'
A$$ROOT
B$details
C$root
D$_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using $$ROOT instead of $details causes no change.
Using $root or $_id replaces with wrong fields.
2fill in blank
medium

Complete the code to replace the root with the "info" field inside "profile".

MongoDB
db.collection.aggregate([{ $replaceRoot: { newRoot: [1] } }])
Drag options to blanks, or click blank then click option'
A$info.profile
B$profile.info.details
C$profile_info
D$profile.info
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of fields like $info.profile is incorrect.
Using underscores instead of dots breaks the path.
3fill in blank
hard

Fix the error in the code to correctly replace the root with the "address" field.

MongoDB
db.collection.aggregate([{ $replaceRoot: { newRoot: [1] } }])
Drag options to blanks, or click blank then click option'
A$address
Baddress
C$$address
Daddress$
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar sign causes an error.
Using double dollar signs or trailing dollar signs is invalid.
4fill in blank
hard

Fill both blanks to replace the root with the "contact" field and rename it to "info".

MongoDB
db.collection.aggregate([{ $replaceRoot: { newRoot: { [1]: [2] } } }])
Drag options to blanks, or click blank then click option'
Ainfo
B$contact
C$info
Dcontact
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field path for the value.
Swapping key and value positions.
5fill in blank
hard

Fill all three blanks to replace the root with a new object containing "name", "email", and "phone" fields from "user".

MongoDB
db.collection.aggregate([{ $replaceRoot: { newRoot: { name: [1], email: [2], phone: [3] } } }])
Drag options to blanks, or click blank then click option'
A$user.name
B$user.email
C$user.phone
D$user.contact
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field paths or mixing keys.
Using a non-existent field like $user.contact.