简体   繁体   English

如何使用 TypeScript 从 Firebase Firestore 文档中获取数据字段?

[英]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.此功能在 Cloud Functions 中,我想知道如何仅获取特定文档的一个字段,而不仅仅是获取所有文档数据。 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. Firestore 客户端 SDK 始终检索整个文档。 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.这个选项确实存在于服务器端/管理 SDK 中,例如 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有关更多信息,请参阅How to access a specific field from Cloud FireStore Firebase in SwiftFirestore 获取文档,除了某些字段

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Typescript 从 Firestore 中的特定文档中获取文档字段? - How do I get a document field from a specific document in Firestore using Typescript? 如何使用 NextJs API、Firebase Firestore、axios 和 TypeScript 从 Firebase 集合中获取数据? - How do I get data from Firebase collection using NextJs API, Firebase Firestore, axios and TypeScript? 如何使用 typescript 中的 function 从 Firestore 获取文档? - how to get a document from firestore using a function in typescript? 如何使用 typescript 或 javascript 从 firestore 中的文档获取字段值并放入 console.log()? - How can I get a field value from a document in firestore with typescript or javascript and put in a console.log()? 如何在Firebase函数(类型脚本)中为从Firestore检索的数据分配Class? - How to assign Class to data retrieved from Firestore in Firebase functions(typescript)? 如何使用angular / typescript从Firebase获取数据并以html显示 - How to get data and display in html from firebase using angular/typescript 从角度Firebase Firestore数据库获取数据 - get data from angular firebase firestore database Firestore 获取文档的根字段 - Firestore get roots field of a document 如何使用Angular Firestore(Angular 7)返回Firebase文档属性? - How to return Firebase document property using Angular Firestore (Angular 7)? 如何删除 Firestore 文档中的字段? - How to delete a field in a Firestore Document?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM