【问题标题】:Why am I getting TypeErrors 'x' is not a function with firebase collection query?为什么我收到 TypeErrors \'x\' is not a function with firebase collection query?
【发布时间】:2022-08-22 23:28:55
【问题描述】:

我的 js 文件在 DOM 中正确输入,我在 firebase.js 文件中初始化了 firebase。为什么我收到 TypeError \'collection(...).doc is not a function\' - 集合查询直接取自 firebase 文档站点,我不明白这怎么可能是类型错误。有什么想法吗?

import { app } from \"./firebase\";
import { getFirestore, doc, collection } from \"firebase/firestore\";

const db = getFirestore(app);

// get data

const docRef = collection(db, \'posts\').doc(\'ARt1ctrEjweKEd4gmgCr\');
await docRef.get();
if (!doc.exists) {
  console.log(\'No such document!\');
} else {
  console.log(\'Document data:\', doc.data());
}

    标签: javascript firebase google-cloud-firestore


    【解决方案1】:

    doc() 是 Modular SDK 中的顶级函数,而不是 collection() 上的方法。尝试:

    const docRef = doc(db, 'posts', 'ARt1ctrEjweKEd4gmgCr');
    

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 2020-09-13
      • 2022-06-22
      • 2021-11-20
      • 2018-10-28
      • 1970-01-01
      • 2015-08-10
      • 2019-09-03
      • 2020-01-20
      相关资源
      最近更新 更多