Complete the code to create a new document with a specific ID in Firestore.
db.collection('users').doc([1]).set({name: 'Alice'});
To create a document with a specific ID, you pass the ID as a string to doc(). Auto-generated IDs require a different method.
Complete the code to add a new document with an auto-generated ID in Firestore.
db.collection('orders').[1]({item: 'book', quantity: 1});
doc() without arguments but forgetting to call set().set() directly on the collection, which is invalid.The add() method adds a new document with an auto-generated ID to the collection.
Fix the error in the code to generate a unique document ID before setting data.
const newDocRef = db.collection('products').[1](); newDocRef.set({name: 'Pen', price: 1.5});
add() on the collection and then trying to call set() on the result.doc() when you want an auto-generated ID.Calling doc() without arguments creates a reference with a unique auto-generated ID. Then you can call set() on it.
Fill both blanks to create a document with a custom ID and set data in Firestore.
const customId = [1]; db.collection('customers').doc(customId).[2]({email: 'user@example.com'});
add() instead of set() when specifying a custom ID.You assign a string as a custom ID, then call set() on the document reference to save data.
Fill all three blanks to generate a new document ID, get its ID string, and set data in Firestore.
const newDoc = db.collection('invoices').[1](); const docId = newDoc.[2]; newDoc.[3]({total: 100});
add() instead of doc() when needing the document ID before setting data.id() as a function instead of accessing the property.Use doc() to create a new document reference with an auto-generated ID, access the ID with id, and save data with set().