0
0
Firebasecloud~10 mins

Array update operations (arrayUnion, arrayRemove) 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 add a new item to the array field in Firestore using arrayUnion.

Firebase
docRef.update({ items: firebase.firestore.FieldValue.[1](['newItem']) });
Drag options to blanks, or click blank then click option'
AarrayUnion
BarrayRemove
Cincrement
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using arrayRemove instead of arrayUnion.
Using set which replaces the whole field.
2fill in blank
medium

Complete the code to remove an item from the array field in Firestore using arrayRemove.

Firebase
docRef.update({ tags: firebase.firestore.FieldValue.[1](['oldTag']) });
Drag options to blanks, or click blank then click option'
Aincrement
BarrayUnion
CarrayRemove
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using arrayUnion which adds instead of removes.
Using delete which deletes the whole field.
3fill in blank
hard

Fix the error in the code to correctly add multiple items to an array field using arrayUnion.

Firebase
docRef.update({ list: firebase.firestore.FieldValue.[1]('item1', 'item2') });
Drag options to blanks, or click blank then click option'
AarrayRemove
Bincrement
Cset
DarrayUnion
Attempts:
3 left
💡 Hint
Common Mistakes
Passing items as a single string instead of separate arguments.
Using arrayRemove which removes items.
4fill in blank
hard

Fill both blanks to update the array field by removing 'oldValue' and adding 'newValue'.

Firebase
docRef.update({ data: firebase.firestore.FieldValue.[1](['oldValue']) });
docRef.update({ data: firebase.firestore.FieldValue.[2](['newValue']) });
Drag options to blanks, or click blank then click option'
AarrayRemove
BarrayUnion
Cset
Dincrement
Attempts:
3 left
💡 Hint
Common Mistakes
Using arrayUnion for removal.
Trying to do both in one call incorrectly.
5fill in blank
hard

Fill all three blanks to remove 'x', add 'y', and add multiple items 'a' and 'b' to the array field.

Firebase
docRef.update({ arr: firebase.firestore.FieldValue.[1](['x']) });
docRef.update({ arr: firebase.firestore.FieldValue.[2](['y']) });
docRef.update({ arr: firebase.firestore.FieldValue.[3]('a', 'b') });
Drag options to blanks, or click blank then click option'
AarrayRemove
BarrayUnion
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using set which replaces the whole array.
Trying to remove with arrayUnion.