Complete the code to define a Firestore document reference for a user with ID 'user123'.
const userRef = firestore.collection('users').[1]('user123');
The doc method gets a reference to a specific document by ID.
Complete the code to add a new document with data to the 'orders' collection.
firestore.collection('orders').[1]({ item: 'book', quantity: 1 });
The add method creates a new document with an auto-generated ID in the collection.
Fix the error in the code to update the user's email in Firestore.
firestore.collection('users').doc('user123').[1]({ email: 'new@example.com' });
The update method modifies existing fields without overwriting the whole document.
Fill both blanks to create a query that gets all orders where quantity is greater than 5.
firestore.collection('orders').[1]('quantity', '[2]', 5).get();
The where method filters documents, and the operator '>' selects quantities greater than 5.
Fill all three blanks to create a map of user IDs to their email addresses for users with active status.
const activeUsers = {};
firestore.collection('users').where('status', '==', 'active').get().then(snapshot => {
snapshot.forEach(doc => {
activeUsers[doc.[1]] = doc.data().[2];
});
console.log(activeUsers); // Maps [3] to emails
});Use doc.id to get the user ID, doc.data().email for the email, and the map links user IDs to emails.