0
0
Firebasecloud~10 mins

Document ID strategies 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 create a new document with a specific ID in Firestore.

Firebase
db.collection('users').doc([1]).set({name: 'Alice'});
Drag options to blanks, or click blank then click option'
A'user123'
Bdb.collection('users').doc().id
Cdb.collection('users').doc().autoId()
Ddb.collection('users').doc().id()
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to get an auto-generated ID by calling a method on doc() that doesn't exist.
Passing a method call instead of a string as the document ID.
2fill in blank
medium

Complete the code to add a new document with an auto-generated ID in Firestore.

Firebase
db.collection('orders').[1]({item: 'book', quantity: 1});
Drag options to blanks, or click blank then click option'
Aset
Bdoc
Cadd
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using doc() without arguments but forgetting to call set().
Using set() directly on the collection, which is invalid.
3fill in blank
hard

Fix the error in the code to generate a unique document ID before setting data.

Firebase
const newDocRef = db.collection('products').[1]();
newDocRef.set({name: 'Pen', price: 1.5});
Drag options to blanks, or click blank then click option'
Adoc
Bdoc('uniqueId')
Cadd()
Dset()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling add() on the collection and then trying to call set() on the result.
Passing a string to doc() when you want an auto-generated ID.
4fill in blank
hard

Fill both blanks to create a document with a custom ID and set data in Firestore.

Firebase
const customId = [1];
db.collection('customers').doc(customId).[2]({email: 'user@example.com'});
Drag options to blanks, or click blank then click option'
A'cust_001'
Badd
Cset
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using add() instead of set() when specifying a custom ID.
Passing a variable instead of a string literal for the custom ID.
5fill in blank
hard

Fill all three blanks to generate a new document ID, get its ID string, and set data in Firestore.

Firebase
const newDoc = db.collection('invoices').[1]();
const docId = newDoc.[2];
newDoc.[3]({total: 100});
Drag options to blanks, or click blank then click option'
Adoc
Bid
Cset
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using add() instead of doc() when needing the document ID before setting data.
Trying to call id() as a function instead of accessing the property.