[英]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 Swift , Firestore 获取文档,除了某些字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.