简体   繁体   中英

How to get a data field from a Firebase Firestore document using TypeScript?

This function is in Cloud Functions, I would like to know how I can get only one field of a specific document, and not just fetch all document data. My Code:

export const onNewOrder = functions.firestore.document("/orders/{orderId}").onCreate(async (snapshot, context) => {
  const orderId = context.params.orderId;

  // Where do I specify the data from which field I want to fetch?
  const snap = await admin.firestore().collection("orders").doc(orderId).get();
  console.log(snap.data());
});

Where do I specify the data from which field I want to fetch?

Firestore client-side SDKs always retrieve the entire document. There is no way to specify that only certain fields should be retrieved from the server.

This option does exist in the server-side/Admin SDKs, such as the one for Node.js.

For more on this, see How to access a specific field from Cloud FireStore Firebase in Swift , Firestore get document except some fields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM