我目前在使用 Firebase 的本機應用程式中遇到這個問題:
集合參考必須有奇數個段
我在 stackoverflow 中看到過類似的情況,但無法解決我的問題。這是我的代碼:
const getData = async () => {
console.log(user.uid " ??????")
const col = collection(db, "users", user.uid)
const taskSnapshot = await getDoc(col)
console.log(taskSnapshot)
}
getData()
我正在嘗試使用檔案參考 (user.uid) 打開我的檔案,但出現此錯誤:Collection references must have an odd number of segments
希望你能幫我解決這個問題。
uj5u.com熱心網友回復:
將DocumentReferencegetDoc()作為引數而不是CollectionReference,因此您必須使用代替。doc()collection()
import { doc, getDoc } from "firebase/firestore"
const docRef = doc(db, "users", user.uid)
const taskSnapshot = await getDoc(col)
console.log(taskSnapshot.data() || "Doc does not exists")
另請查看 Firestore:在 Web v9 中添加新資料的模式是什么?
uj5u.com熱心網友回復:
替換這個
collection(db, "users", user.uid)
有了這個
collection(db).document("users").collection(user.uid)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/533733.html
標籤:Google Cloud Collective javascript火力基地google-cloud-firestore
