Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new collection named 'users'.
Firebase
const usersCollection = firestore.collection('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong collection name like 'documents' or 'data'.
✗ Incorrect
The collection name must be 'users' to create the correct collection.
2fill in blank
mediumComplete the code to add a new document with ID 'user123' to the 'users' collection.
Firebase
firestore.collection('users').doc('[1]').set({ name: 'Alice' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic ID like 'userId' or a wrong ID like '123user'.
✗ Incorrect
The document ID must be 'user123' to match the intended document.
3fill in blank
hardFix the error in the code to correctly add a document with auto-generated ID.
Firebase
firestore.collection('users').[1]({ name: 'Bob' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' without specifying a document ID causes an error.
✗ Incorrect
The 'add' method creates a new document with an auto-generated ID.
4fill in blank
hardFill both blanks to create a document reference and set data in it.
Firebase
const docRef = firestore.collection('[1]').doc('[2]'); docRef.set({ age: 30 });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing collection and document names or using wrong IDs.
✗ Incorrect
The collection is 'employees' and the document ID is 'emp001' as required.
5fill in blank
hardFill all three blanks to create a nested collection and add a document with data.
Firebase
const docRef = firestore.collection('[1]').doc('[2]').collection('[3]'); docRef.add({ status: 'active' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong collection or document names or mixing levels.
✗ Incorrect
The code creates a 'tasks' collection inside the 'projA' document of 'projects' collection.