Complete the code to initialize Firestore in a Firebase app.
const db = firebase.[1]();The firestore() method initializes Firestore, Firebase's primary database.
Complete the code to add a document to a Firestore collection.
db.collection('users').[1]({ name: 'Alice', age: 30 });
The add() method adds a new document with an auto-generated ID to the collection.
Fix the error in the code to get a document by ID from Firestore.
db.collection('users').doc([1]).get().then(doc => { if (doc.exists) { console.log(doc.data()); } });
The document ID must be a string. Using quotes around 'userId' passes the ID correctly.
Fill both blanks to query Firestore for users older than 25 and order by age.
db.collection('users').where('age', [1], 25).[2]('age').get();
The where clause filters users older than 25 using '>'. The orderBy method sorts results by age.
Fill all three blanks to update a user's email and log success.
db.collection('users').doc([1]).[2]({ email: [3] }).then(() => { console.log('Email updated'); });
set overwrites the whole document.The doc method needs the document ID as a string. The update method changes fields without overwriting the whole document. The new email must be a string.