0
0
Firebasecloud~20 mins

JSON tree structure in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase JSON Tree Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Firebase JSON Tree Structure Output
Given the Firebase Realtime Database JSON tree below, what is the value returned when querying the path /users/user1/age?
Firebase
{
  "users": {
    "user1": {
      "name": "Alice",
      "age": 30,
      "active": true
    },
    "user2": {
      "name": "Bob",
      "age": 25,
      "active": false
    }
  }
}
A"Alice"
Btrue
C30
Dnull
Attempts:
2 left
💡 Hint
Look at the path and find the value stored under 'age' for 'user1'.
Architecture
intermediate
2:30remaining
Firebase JSON Tree Structure and Data Nesting
Which of the following JSON structures best represents a Firebase Realtime Database tree optimized to avoid deeply nested data for storing blog posts and their comments?
A
{
  "posts": {
    "post1": {
      "title": "Hello"
    }
  },
  "comments": {
    "post1": {
      "comment1": "Nice post!",
      "comment2": "Thanks for sharing"
    }
  }
}
B
{
  "posts": {
    "post1": {
      "title": "Hello",
      "comments": [
        "Nice post!",
        "Thanks for sharing"
      ]
    }
  }
}
C
{
  "posts": {
    "post1": {
      "title": "Hello",
      "comments": {
        "comment1": "Nice post!",
        "comment2": "Thanks for sharing"
      }
    }
  }
}
D
{
  "posts": {
    "post1": {
      "title": "Hello",
      "comments": "Nice post!"
    }
  }
}
Attempts:
2 left
💡 Hint
Firebase recommends flattening data to avoid deep nesting.
security
advanced
3:00remaining
Firebase JSON Tree Security Rules Impact
Given the Firebase Realtime Database JSON tree below, which security rule will allow only authenticated users to read their own profile data under /users/{userId} but deny access to others?
Firebase
{
  "users": {
    "user1": {"name": "Alice"},
    "user2": {"name": "Bob"}
  }
}
A
{
  "rules": {
    "users": {
      "$userId": {
        ".read": "auth != null",
        ".write": "auth != null"
      }
    }
  }
}
B
{
  "rules": {
    "users": {
      "$userId": {
        ".read": "auth != null && auth.uid == $userId",
        ".write": "auth != null && auth.uid == $userId"
      }
    }
  }
}
C
{
  "rules": {
    "users": {
      ".read": "auth != null",
      ".write": "auth != null"
    }
  }
}
D
{
  "rules": {
    "users": {
      "$userId": {
        ".read": "true",
        ".write": "auth != null && auth.uid == $userId"
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Check the condition that matches the authenticated user's ID to the data path.
Configuration
advanced
2:30remaining
Firebase JSON Tree Update Behavior
If you perform an update operation on the Firebase Realtime Database path /users/user1 with the JSON {"age": 31}, what will be the resulting JSON subtree under /users/user1 given the initial data below?
Firebase
{
  "users": {
    "user1": {
      "name": "Alice",
      "age": 30,
      "active": true
    }
  }
}
A
{
  "name": "Alice",
  "age": 31,
  "active": true
}
B
{
  "age": 31
}
C
{
  "name": "Alice",
  "age": 30,
  "active": true
}
D
{
  "name": "Alice",
  "active": true
}
Attempts:
2 left
💡 Hint
Firebase update merges keys, it does not replace the entire node.
🧠 Conceptual
expert
3:00remaining
Analyzing Firebase JSON Tree Data Consistency
Consider a Firebase Realtime Database JSON tree where user profiles and their posts are stored separately as below. If a user deletes their profile, what is the best approach to ensure no orphan posts remain in the database?
Firebase
{
  "users": {
    "user1": {"name": "Alice"}
  },
  "posts": {
    "post1": {"author": "user1", "content": "Hello"},
    "post2": {"author": "user1", "content": "World"}
  }
}
ANo action needed; orphan posts do not affect database consistency.
BManually delete posts before deleting the user profile to avoid orphan posts.
CRely on Firebase Realtime Database rules to automatically delete posts when user is deleted.
DUse Firebase Cloud Functions to trigger on user deletion and remove all posts with matching author ID.
Attempts:
2 left
💡 Hint
Think about automating cleanup to maintain data integrity.