firebase db.collection不是Firestore的函数[重复]

3df52oht  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(83)

此问题在此处已有答案

db.collection is not a function firebase firestore(2个答案)
Firebase Firestore db.collection is not a function(1个答案)
TypeError: db.collection is not a function at handleSignIn [duplicate](1个答案)
28天前关闭。
根据Firebase文档,我们可以在Firestore中使用点表示法。当我在客户端浏览器中运行以下代码时:

import { getFirestore, collection, doc } from "firebase/firestore";
let  db = getFirestore(app);
db.collection("users").doc("123").set({ name: "Mike"});

字符串
我得到以下错误:
第一个月
我不知道问题出在哪里。文档是最新的吗?

8ehkhllq

8ehkhllq1#

我认为这些信息是针对不同版本的Firebase的。您正在将collection & doc作为函数导入,并且它们需要像这样运行。

import { getFirestore, collection, doc, updateDoc } from "firebase/firestore";
...
const db = getFirestore(app);
const usersCollection = collection(db, "users");
const docRef = doc(usersCollection, "123");
await updateDoc (docRef, { name: "Mike"});

字符串

相关问题