【问题标题】:Subcollection in FirestoreFirestore 中的子集合
【发布时间】:2021-10-15 13:30:51
【问题描述】:

我无法在不存在的子集合中创建文档。

我有一个用户集合,其中包含一个以 userId 作为 Id 的文档。 在本文档中我想要一个子集合订单

还没有创建订单子集合。但是你不能创建空的子集合。

所以我这样做:

const OrderID = 1; //just for testing
const ref = doc(
        db,
        "users",
        getAuth().currentUser.uid,
        "orders",
        OrderID
      );

但这不起作用。

我该怎么做?

【问题讨论】:

    标签: javascript firebase google-cloud-firestore


    【解决方案1】:

    好的,找到了 OrderID 不能是数字。它必须是一个字符串。我得到的错误并没有告诉我。它抱怨一个超出范围的功能.....

    const OrderID = 1; //just for testing
    const ref = doc(
            db,
            "users",
            getAuth().currentUser.uid,
            "orders",
            OrderID.toString()
          );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      • 2019-07-25
      • 2019-02-17
      • 1970-01-01
      相关资源
      最近更新 更多