Recall & Review
beginner
What does the add() method do when adding a document in Firebase?
The add() method creates a new document with a unique ID automatically generated by Firebase in a collection.
Click to reveal answer
beginner
How does the set() method differ from add() when adding documents?
set() writes data to a document with a specified ID. It can create or overwrite the document, unlike add() which auto-generates the ID.
Click to reveal answer
beginner
Can you specify a document ID when using add() in Firebase?
No, add() automatically generates a unique document ID. To specify an ID, you must use set() with a document reference.
Click to reveal answer
intermediate
What happens if you use set() on an existing document?
Using set() on an existing document overwrites its data completely unless you use the merge option to keep existing fields.
Click to reveal answer
beginner
When should you prefer add() over set()?
Use add() when you want Firebase to generate a unique ID automatically and you don't need to control the document ID.
Click to reveal answer
Which method automatically generates a unique document ID in Firebase?
✗ Incorrect
add() creates a new document with a unique ID automatically generated by Firebase.
Which method allows you to specify the document ID when adding data?
✗ Incorrect
set() writes data to a document with a specified ID.
What happens if you use
set() on an existing document without merge option?✗ Incorrect
set() overwrites the entire document unless merge option is used.If you want Firebase to handle document IDs automatically, which method should you use?
✗ Incorrect
add() automatically generates document IDs.
Which method is best when you need to update or create a document with a known ID?
✗ Incorrect
set() lets you specify the document ID and create or overwrite it.
Explain the difference between
add() and set() methods in Firebase when adding documents.Think about how document IDs are handled and whether you control them.
You got /4 concepts.
When would you choose to use
add() instead of set() in your Firebase app?Consider ease and control over document IDs.
You got /4 concepts.