为了账号安全,请及时绑定邮箱和手机立即绑定

从 Firestore 文档中读取字段的最简单方法

从 Firestore 文档中读取字段的最简单方法

慕标5832272 2021-10-21 16:19:18
我一直在为这个简单的问题绕圈子:我试图读取 Firestore 文档中的一个字段。我正在寻找最直接的解决方案,让我可以使用常量。const userId = context.params.userId;const customer = admin.firestore()        .collection('stripe_customers')        .doc(userId)        .collection('customer_info')        .data('customer_id');云函数日志给了我这个:类型错误:admin.firestore(...).collection(...).doc(...).collection(...).data 不是函数同样的错误.data().customer_id;这是我尝试过的另一种选择:const customerDoc = admin.firestore()        .collection('stripe_customers')        .doc(userId)        .collection('customer_info')        .doc('customer_object');        const customer = customerDoc.get('customer_id');        console.log(customer);使用此选项,控制台会记录一个挂起的承诺。不知道如何处理。我经历了比我想象的更多的尝试并且已经用尽了文档。如果有人知道如何以直接的方式做到这一点,请告诉我。
查看完整描述

1 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

我一直在为这个简单的问题绕圈子:我试图读取 Firestore 文档中的一个字段。我正在寻找最直接的解决方案,让我可以使用常量。


const userId = context.params.userId;


const customer = admin.firestore()

        .collection('stripe_customers')

        .doc(userId)

        .collection('customer_info')

        .data('customer_id');

云函数日志给了我这个:


类型错误:admin.firestore(...).collection(...).doc(...).collection(...).data 不是函数


同样的错误


.data().customer_id;

这是我尝试过的另一种选择:


const customerDoc = admin.firestore()

        .collection('stripe_customers')

        .doc(userId)

        .collection('customer_info')

        .doc('customer_object');


        const customer = customerDoc.get('customer_id');


        console.log(customer);

使用此选项,控制台会记录一个挂起的承诺。不知道如何处理。


我经历了比我想象的更多的尝试并且已经用尽了文档。如果有人知道如何以直接的方式做到这一点,请告诉我。


查看完整回答
反对 回复 2021-10-21
  • 1 回答
  • 0 关注
  • 179 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信