嘿,我正在嘗試使用以下命令在 firebase 中獲取某個集合的所有檔案:
const userCollectionRef = collection(db, currentUser?.uid)
const snapshot = await userCollectionRef.get()
for (const doc of snapshot) {
console.log(doc.id)
}
問題:
TypeError: userCollectionRef.get is not a function
我的進口:
import { db } from '../firebase'
import { collection } from 'firebase/firestore'
uj5u.com熱心網友回復:
getDocs()您可以使用CollectionReferenceV9 SDK 中的一個頂級函式來獲取多個檔案:
import { collection, getDocs } from "firebase/firestore";
const userCollectionRef = collection(db, currentUser?.uid)
const snapshot = await getDocs(userCollectionRef)
const data = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }))
查看檔案以獲取更多資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/492822.html
標籤:javascript 反应 火力基地 谷歌云火库
