Challenge - 5 Problems
Array Operations Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate1:30remaining
What is the final array after using arrayUnion?
You have a Firestore document with a field
tags containing ["cloud", "storage"]. You run an update with arrayUnion("storage", "database"). What will be the new value of tags?Attempts:
2 left
💡 Hint
arrayUnion adds elements only if they are not already present.
✗ Incorrect
The arrayUnion operation adds elements to the array only if they do not already exist. Since "storage" is already present, it is not duplicated. "database" is added.
❓ service_behavior
intermediate1:30remaining
What happens when arrayRemove removes a non-existing element?
A Firestore document has a field
features with value ["auth", "hosting"]. You run an update with arrayRemove("functions"). What will be the value of features after the update?Attempts:
2 left
💡 Hint
arrayRemove only removes elements if they exist.
✗ Incorrect
If the element to remove does not exist in the array, the array remains unchanged.
❓ Configuration
advanced2:00remaining
Which update operation correctly adds multiple unique elements to an array field?
You want to update a Firestore document's
permissions array to add "read" and "write" without duplicates. Which update code snippet is correct?Attempts:
2 left
💡 Hint
arrayUnion accepts multiple arguments, not an array argument.
✗ Incorrect
arrayUnion takes multiple elements as separate arguments to add them uniquely. Passing an array as a single argument adds the array as one element, not its contents.
❓ security
advanced2:00remaining
What is a security risk when using arrayUnion with user input?
If you use
arrayUnion to add user-provided tags to a Firestore array field without validation, what risk might occur?Attempts:
2 left
💡 Hint
Think about what happens if you trust user input blindly.
✗ Incorrect
Using arrayUnion with unchecked user input can allow users to add unwanted or harmful data to your database, which can affect data quality and security.
❓ Architecture
expert2:30remaining
How to efficiently maintain a unique list of active users in Firestore using array operations?
You want to keep a Firestore document field
activeUsers updated with unique user IDs as users become active or inactive. Which approach best ensures uniqueness and efficient updates?Attempts:
2 left
💡 Hint
Consider how arrayUnion and arrayRemove work for adding/removing unique elements.
✗ Incorrect
Using arrayUnion and arrayRemove ensures that user IDs are added or removed uniquely without duplicates or overwriting the entire array, making updates efficient and safe.