Hi can you please help me I am trying to store user credential in firestore after they have signup but I keep getting this errorInvalid collection reference. Collection references must have an odd number of segments, but userDatabase/QMJiHnhoCchs6MKmPFk7wzTrlau1 has 2.
below is my code Many thankconst db = getFirestore(app)
//Sign up User Method
createUserWithEmailAndPassword( auth, email, password)
.then((res) => {
// Signed in
const uid = res.user.uid;
const data = {
id:uid,
email,
name,
};
const ref = collection(db, 'userDatabase',uid)
console.log(ref);
setDoc(ref, data)
.then(() => console.log("Created New User Document Successfully"))
.catch((e) => console.log("Error" , e));
).catch((e)=>console.log(e))
After I commented all the line from the createUserWithEmailAndPassword I notice that thisconst ref = collection(db, 'userDatabase',uid)
line was the one generating the error but I can't just figure out why I have tried several methods to resolve this issues which have not work.
createUserWithEmailAndPassword(auth, email, password)
.then((res) => {
// Signed in
const uid = res.user.uid;
// const data = {
// id:uid,
// email,
// name,
//};
const ref = collection(db, 'userDatabase',uid)
console.log(ref);
//setDoc(ref, data)
// .then(() => console.log("Created New User Document Successfully"))
// .catch((e) => console.log("Error" , e));
1条答案
按热度按时间flvlnr441#
我通过将
collection
替换为doc
来解决此问题首先确保从firebase/firebase导入doc,如下所示
然后更改此项
结束日期