Google Professional Cloud Developer Question 449
Single answerGoogle Cloud PlatformYou are developing a RESTful API using Google Cloud Functions to serve data from a Firestore database. Your API should only return specific fields from the Firestore documents to avoid exposing sensitive information. Which approach should you use to restrict the return data?
- A
Use Firestore's 'select()' method to specify which fields to include in the query results.
- B
Filter out sensitive fields in the client application after retrieving the full Firestore document.
- C
Use the Firestore security rules to explicitly allow access only to specific fields.
- D
Pass the sensitive fields as null values in the API response.
Show answer and explanation
Correct answer: A
Explanation
To restrict return data effectively, it is best to use Firestore's 'select()' method. This ensures that only the specified fields are retrieved from the database and included in the API response. Filtering fields on the client-side or using null values does not adequately address the requirement to restrict return data, and Firestore security rules are intended for access control rather than field selection.
- A. Correct.
Correct: Firestore's 'select()' method allows you to specify which fields to include in the query results, ensuring only the necessary data is retrieved.
- B. Incorrect.
Incorrect: Filtering out fields in the client application does not restrict the data returned from the database and exposes sensitive information during transport.
- C. Incorrect.
Incorrect: While Firestore security rules are important for securing access, they do not control the fields returned in query results.
- D. Incorrect.
Incorrect: Passing null values for sensitive fields still includes those fields in the response, which may not meet the objective of restricting return data.