0
0
Firebasecloud~10 mins

Fan-out writes pattern in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a fan-out update object for Firebase Realtime Database.

Firebase
const updates = {};
updates['/posts/' + postId] = postData;
updates[[1]] = postData;
return firebase.database().ref().update(updates);
Drag options to blanks, or click blank then click option'
A'/posts/' + userId + '/' + postId
B'/user-posts/' + userId + '/' + postId
C'/user-posts/' + postId
D'/posts/' + userId
Attempts:
3 left
💡 Hint
Common Mistakes
Using only postId without userId in the path.
Mixing up the order of userId and postId in the path.
2fill in blank
medium

Complete the code to perform a fan-out write using Firebase Admin SDK.

Firebase
const updates = {};
updates['/messages/' + messageId] = messageData;
updates[[1]] = messageData;
return admin.database().ref().update(updates);
Drag options to blanks, or click blank then click option'
A'/user-messages/' + messageId
B'/messages/' + userId + '/' + messageId
C'/user-messages/' + userId + '/' + messageId
D'/messages/' + userId
Attempts:
3 left
💡 Hint
Common Mistakes
Using only messageId without userId in the path.
Using the wrong base path for user messages.
3fill in blank
hard

Fix the error in the fan-out write code to correctly update both paths.

Firebase
const updates = {};
updates['/comments/' + commentId] = commentData;
updates[[1]] = commentData;
return firebase.database().ref().update(updates);
Drag options to blanks, or click blank then click option'
A'/user-comments/' + commentId
B'/comments/' + commentId
C'/comments/' + userId + '/' + commentId
D'/user-comments/' + userId + '/' + commentId
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting userId in the user-specific path.
Using the wrong base path for user comments.
4fill in blank
hard

Fill both blanks to create a fan-out write that updates posts and user-posts paths.

Firebase
const updates = {};
updates[[1]] = postData;
updates[[2]] = postData;
return admin.database().ref().update(updates);
Drag options to blanks, or click blank then click option'
A'/posts/' + postId
B'/posts/' + userId + '/' + postId
C'/user-posts/' + userId + '/' + postId
D'/user-posts/' + postId
Attempts:
3 left
💡 Hint
Common Mistakes
Using userId in the general posts path.
Omitting userId in the user-posts path.
5fill in blank
hard

Fill all three blanks to complete the fan-out write for messages, user-messages, and user-inbox paths.

Firebase
const updates = {};
updates[[1]] = messageData;
updates[[2]] = messageData;
updates[[3]] = true;
return firebase.database().ref().update(updates);
Drag options to blanks, or click blank then click option'
A'/messages/' + messageId
B'/user-messages/' + userId + '/' + messageId
C'/user-inbox/' + userId + '/' + messageId
D'/messages/' + userId + '/' + messageId
Attempts:
3 left
💡 Hint
Common Mistakes
Using userId in the general messages path.
Omitting userId in user-specific paths.
Using incorrect values for the inbox update.