0
0
Firebasecloud~10 mins

Data denormalization strategies 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 denormalized data structure for a user's profile in Firebase.

Firebase
const userProfile = {
  name: "Alice",
  age: 30,
  posts: [1]
};
Drag options to blanks, or click blank then click option'
A["post1", "post2"]
B"post1"
C{post1: true, post2: true}
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string instead of a list for multiple posts.
Using an object with true values which is less straightforward here.
2fill in blank
medium

Complete the code to update a user's post count in a denormalized Firebase database.

Firebase
firebase.database().ref('users/' + userId).update({
  postCount: [1]
});
Drag options to blanks, or click blank then click option'
Aposts
BpostsCount
Cposts.length
DpostCount + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length of posts array directly without updating.
Using an undefined variable like postsCount.
3fill in blank
hard

Fix the error in the denormalized data update code to avoid overwriting unrelated data.

Firebase
firebase.database().ref('posts/' + postId).update({
  title: newTitle,
  content: newContent,
  [1]: newTimestamp
});
Drag options to blanks, or click blank then click option'
AupdatedAt
BcreatedAt
Ctimestamp
Dtime
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'createdAt' which does not change on updates.
Using generic names like 'time' which are unclear.
4fill in blank
hard

Fill both blanks to correctly denormalize user data and posts in Firebase.

Firebase
const denormalizedData = {
  users: {
    [1]: {
      name: userName,
      postCount: [2]
    }
  }
};
Drag options to blanks, or click blank then click option'
AuserId
BuserName
CpostCount
Dposts
Attempts:
3 left
💡 Hint
Common Mistakes
Using userName as a key instead of userId.
Using posts array instead of postCount for the count.
5fill in blank
hard

Fill all three blanks to correctly update denormalized post data with user info in Firebase.

Firebase
firebase.database().ref('posts/' + [1]).update({
  title: newTitle,
  authorName: [2],
  authorId: [3]
});
Drag options to blanks, or click blank then click option'
ApostId
BuserName
CuserId
DpostKey
Attempts:
3 left
💡 Hint
Common Mistakes
Using postKey instead of postId which may not be defined.
Mixing up userName and userId positions.