Complete the code to replace the root document with the "details" field.
db.collection.aggregate([{ $replaceRoot: { newRoot: [1] } }])The $replaceRoot stage replaces the root document with the specified field. Using $details sets the root to the "details" field.
Complete the code to replace the root with the "info" field inside "profile".
db.collection.aggregate([{ $replaceRoot: { newRoot: [1] } }])To replace the root with a nested field, use the full path with dot notation. Here, $profile.info points to the "info" field inside "profile".
Fix the error in the code to correctly replace the root with the "address" field.
db.collection.aggregate([{ $replaceRoot: { newRoot: [1] } }])The newRoot value must be a field path starting with a dollar sign. Using $address correctly references the "address" field.
Fill both blanks to replace the root with the "contact" field and rename it to "info".
db.collection.aggregate([{ $replaceRoot: { newRoot: { [1]: [2] } } }])To rename the root field, create a new object with the desired key "info" and assign it the value of the "contact" field using $contact.
Fill all three blanks to replace the root with a new object containing "name", "email", and "phone" fields from "user".
db.collection.aggregate([{ $replaceRoot: { newRoot: { name: [1], email: [2], phone: [3] } } }])Each field in the new root object should be assigned the corresponding nested field from "user" using dot notation with a dollar sign.