【问题标题】:Google Firebase is not allowing me to append data with db.collection.doc.push.setGoogle Firebase 不允许我使用 db.collection.doc.push.set 附加数据
【发布时间】:2022-02-16 06:30:38
【问题描述】:

我有节点项目,我正在尝试将 google firebase 集成为项目的数据库。我目前拥有它,以便在调用它时可以从数据库中获取数据。我设置了初始记录,现在我正在尝试将记录附加到 google firebase 数据库。

当我调用db.collection(...).doc(...).push().set(...) 时,它给了我一个错误,说没有调用.push() 的函数。我不知道为什么,因为文档说它应该将新记录附加到数据库中。不知道该怎么办。

这是我当前的代码:

  post: (req, res) => {
    const body = req.body;
    newReivew = {
      rating: "",
      user: {
        id: "feaer323vwe",
        profile_url: "",
        image_url: "",
        name: "John Doe Jr",
      },
      text: "Thsi is a third review",
      time_created: "asdffeasvsesv",
      url: "hoots:google.com",
    };
    db.collection("reviews").doc("yelp_reviews").push().set(newReivew);
  },

【问题讨论】:

    标签: node.js firebase google-cloud-firestore


    【解决方案1】:

    push 方法是 Firebase 实时数据库 API 的一部分,在 Firestore 上不存在。虽然这两个数据库都是 Firebase 的一部分,但它们是完全独立的,一个的 API 不一定适用于另一个。

    add a document 到 Firestore,使用 add()

    db.collection("reviews").doc("yelp_reviews").add(newReivew);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多