簡體   English   中英

如何使用 TypeScript 從 Firebase Firestore 文檔中獲取數據字段?

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

此功能在 Cloud Functions 中,我想知道如何僅獲取特定文檔的一個字段,而不僅僅是獲取所有文檔數據。 我的代碼:

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());
});

我在哪里指定要從哪個字段獲取數據?

Firestore 客戶端 SDK 始終檢索整個文檔。 無法指定僅應從服務器檢索某些字段。

這個選項確實存在於服務器端/管理 SDK 中,例如 Node.js 的那個。

有關更多信息,請參閱How to access a specific field from Cloud FireStore Firebase in SwiftFirestore 獲取文檔,除了某些字段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM