Complete the code to get a single document from Firestore.
const docRef = doc(db, 'users', [1]); const docSnap = await getDoc(docRef);
You need to specify the document ID to get a single document. Here, 'userId123' is the document ID.
Complete the code to check if the document exists.
if ([1].exists()) { console.log('Document data:', docSnap.data()); } else { console.log('No such document!'); }
The exists() method is called on the document snapshot object, which is docSnap.
Fix the error in the code to correctly import the Firestore functions.
import { [1] } from 'firebase/firestore';
The correct function to import for getting a document is getDoc.
Fill both blanks to create a document reference and get the document snapshot.
const docRef = [1](db, 'products', [2]); const docSnap = await getDoc(docRef);
Use doc to create a document reference and provide the document ID as the third argument.
Fill all three blanks to check if a document exists and log its data.
if ([1].[2]()) { console.log('Data:', [3].data()); } else { console.log('No document found'); }
You check if the document snapshot docSnap exists by calling exists(), then log its data.
