0
0
Firebasecloud~10 mins

Adding documents (add vs set) in Firebase - Interactive 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 document to the collection using Firestore's add method.

Firebase
db.collection('users').[1]({ name: 'Alice', age: 30 });
Drag options to blanks, or click blank then click option'
Aget
Bset
Cupdate
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using set instead of add when you want Firestore to generate the document ID.
Using update which requires an existing document.
2fill in blank
medium

Complete the code to set data for a document with a specific ID using Firestore's set method.

Firebase
db.collection('users').doc('user123').[1]({ name: 'Bob', age: 25 });
Drag options to blanks, or click blank then click option'
Aset
Badd
Cupdate
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using add which does not allow specifying the document ID.
Using update which fails if the document does not exist.
3fill in blank
hard

Fix the error in the code to correctly add a document with generated ID.

Firebase
db.collection('orders').doc().[1]({ item: 'Book', quantity: 2 });
Drag options to blanks, or click blank then click option'
Aupdate
Badd
Cset
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using add on a document reference instead of a collection.
Using update on a non-existing document.
4fill in blank
hard

Fill both blanks to create a new document with a generated ID and set data in one step.

Firebase
db.collection('products').[1]([2]);
Drag options to blanks, or click blank then click option'
Aadd
B{ name: 'Laptop', price: 1200 }
Cset
D{ id: 'prod1', name: 'Laptop' }
Attempts:
3 left
💡 Hint
Common Mistakes
Using set without specifying a document reference.
Passing an object with an id field to add.
5fill in blank
hard

Fill all three blanks to set data on a document with a specific ID and merge it with existing data.

Firebase
db.collection('customers').doc([1]).[2]([3], { merge: true });
Drag options to blanks, or click blank then click option'
A'cust123'
Bset
C{ phone: '123-456-7890' }
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using add instead of set when specifying a document ID.
Not using merge option and overwriting existing data.