I am currently encountering this problem in my react native app using Firebase:
Collection references must have an odd number of segments
I’ve seen similar cases in stackoverflow but wasn’t able to solve my problem. Here is my code :
const getData = async () => {
console.log(user.uid + " 🚧🚧🚧")
const col = collection(db, "users", user.uid)
const taskSnapshot = await getDoc(col)
console.log(taskSnapshot)
}
getData()
I am trying to open my document with the document reference (user.uid) but I am getting this error : Collection references must have an odd number of segments
Hope you can help me solve this problem.
2
Answers
The
getDoc()
takes a DocumentReference as parameter and not a CollectionReference so you must usedoc()
instead ofcollection()
.Also checkout Firestore: What's the pattern for adding new data in Web v9?
replace this
with this