Bird
0
0

Given this code snippet using Firestore on GCP:

medium📝 Predict Output Q13 of 15
GCP - Cloud Firestore and Bigtable
Given this code snippet using Firestore on GCP:
doc_ref = firestore_client.collection('users').document('user123')
doc_ref.set({'name': 'Alice', 'age': 30})
user = doc_ref.get().to_dict()
print(user['name'])

What will be printed?
Auser123
BAlice
C30
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand Firestore document creation

    The code sets a document with fields 'name' and 'age' under 'users/user123'.
  2. Step 2: Retrieve and print the 'name' field

    The get() call fetches the document, and user['name'] accesses the 'name' value, which is 'Alice'.
  3. Final Answer:

    Alice -> Option B
  4. Quick Check:

    Print user['name'] = Alice [OK]
Quick Trick: Set then get document fields to print values [OK]
Common Mistakes:
  • Printing document ID instead of field
  • Confusing field names
  • Assuming None if document exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes