Google Professional Cloud Developer Question 450
Single answerGoogle Cloud PlatformYou are developing a RESTful API on Google Cloud using Cloud Functions. The API retrieves a large dataset from Firestore but only specific fields from the dataset should be returned to the client. How can you restrict the return data efficiently while maintaining performance and minimizing client-side processing?
- A
Use Firestore projections to query and retrieve only the required fields.
- B
Retrieve the full dataset from Firestore and filter out the unnecessary fields in the client application.
- C
Retrieve the full dataset from Firestore and filter out the unnecessary fields in the Cloud Function before sending the response.
- D
Use a Firestore security rule to restrict the fields being returned to the client.
Show answer and explanation
Correct answer: A
Explanation
Using Firestore projections is the most efficient way to restrict return data because it ensures only the required fields are retrieved from the database. This minimizes the data being transferred over the network, reduces latency, and avoids unnecessary processing in the Cloud Function or client application. While Firestore security rules are important for controlling access, they do not serve the purpose of modifying or filtering the data returned by queries.
- A. Correct.
Correct. Firestore projections allow you to specify the fields to retrieve in queries, which reduces the amount of data being transferred and improves performance.
- B. Incorrect.
Incorrect. Retrieving the full dataset to the client is inefficient and increases bandwidth usage and processing on the client side.
- C. Incorrect.
Incorrect. Filtering data in the Cloud Function still results in retrieving unnecessary fields from Firestore, increasing latency and resource usage.
- D. Incorrect.
Incorrect. Firestore security rules control access to documents and fields but do not filter or modify the data returned by queries.