Bird
0
0

Which of the following is the correct syntax to get a reference to a document named user123 inside a collection users in Firestore using Node.js?

easy📝 Configuration Q12 of 15
GCP - Cloud Firestore and Bigtable
Which of the following is the correct syntax to get a reference to a document named user123 inside a collection users in Firestore using Node.js?
Aconst docRef = firestore.doc('user123/users');
Bconst docRef = firestore.collection('users').doc('user123');
Cconst docRef = firestore.collection('user123').doc('users');
Dconst docRef = firestore.doc('users').doc('user123');
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct method to access collection and document

    Use collection('users') to access the collection, then doc('user123') to get the document.
  2. Step 2: Check path correctness

    Direct firestore.doc(full/path) works for existing paths, but incorrect paths, reversed order, or misusing doc() on document references fail. Chaining collection().doc() is recommended.
  3. Final Answer:

    const docRef = firestore.collection('users').doc('user123'); -> Option B
  4. Quick Check:

    Use collection().doc() chaining for document refs [OK]
Quick Trick: Chain collection() then doc() for document reference [OK]
Common Mistakes:
  • Swapping collection and document names
  • Using firestore.doc() with incorrect path format
  • Confusing collection() and doc() order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes