0
0
Firebasecloud~5 mins

Array update operations (arrayUnion, arrayRemove) in Firebase - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does arrayUnion do in Firebase Firestore?

arrayUnion adds elements to an array field in a document only if they are not already present. It prevents duplicates.

Click to reveal answer
beginner
What is the purpose of arrayRemove in Firebase Firestore?

arrayRemove removes all instances of specified elements from an array field in a document.

Click to reveal answer
intermediate
Can arrayUnion add multiple elements at once?

Yes, you can pass multiple elements to arrayUnion and it will add all unique ones to the array.

Click to reveal answer
intermediate
What happens if you use arrayRemove with an element not in the array?

Nothing changes. arrayRemove only removes elements if they exist; if not, the array stays the same.

Click to reveal answer
advanced
Why are arrayUnion and arrayRemove useful compared to reading and writing the whole array?
<p>They let you update arrays atomically without overwriting the entire array, avoiding conflicts and saving bandwidth.</p>
Click to reveal answer
Which Firebase function adds unique elements to an array field without duplicates?
Aupdate
BarrayRemove
CarrayUnion
Dset
What does arrayRemove do if the element is not in the array?
ADoes nothing
BRemoves the element anyway
CAdds the element
DThrows an error
Can you pass multiple elements to arrayUnion at once?
ANo, only one element
BYes, multiple elements
COnly arrays
DOnly strings
Why use arrayUnion instead of reading and rewriting the whole array?
AIt only works on strings
BIt is slower
CIt deletes the array
DIt avoids overwriting and conflicts
Which operation removes all instances of specified elements from an array field?
AarrayRemove
BarrayUnion
Cset
Dget
Explain how arrayUnion and arrayRemove help manage array fields in Firebase Firestore.
Think about adding and removing items safely without conflicts.
You got /4 concepts.
    Describe a real-life example where using arrayUnion would be better than rewriting the entire array.
    Imagine a shared list where many people add items.
    You got /4 concepts.