Complete the code to create a fan-out update object for Firebase Realtime Database.
const updates = {};
updates['/posts/' + postId] = postData;
updates[[1]] = postData;
return firebase.database().ref().update(updates);In fan-out writes, you update multiple paths. Here, the second path is the user's posts path, which is '/user-posts/' + userId + '/' + postId.
Complete the code to perform a fan-out write using Firebase Admin SDK.
const updates = {};
updates['/messages/' + messageId] = messageData;
updates[[1]] = messageData;
return admin.database().ref().update(updates);The fan-out write updates both the general messages path and the user-specific messages path, which is '/user-messages/' + userId + '/' + messageId.
Fix the error in the fan-out write code to correctly update both paths.
const updates = {};
updates['/comments/' + commentId] = commentData;
updates[[1]] = commentData;
return firebase.database().ref().update(updates);The correct fan-out path includes both userId and commentId to uniquely identify the comment under the user-comments path.
Fill both blanks to create a fan-out write that updates posts and user-posts paths.
const updates = {};
updates[[1]] = postData;
updates[[2]] = postData;
return admin.database().ref().update(updates);The first path is the general posts path '/posts/' + postId, and the second is the user-specific posts path '/user-posts/' + userId + '/' + postId.
Fill all three blanks to complete the fan-out write for messages, user-messages, and user-inbox paths.
const updates = {};
updates[[1]] = messageData;
updates[[2]] = messageData;
updates[[3]] = true;
return firebase.database().ref().update(updates);The fan-out write updates the general messages path, the user-specific messages path, and marks the message as present in the user's inbox with a boolean true.