Reputation: 1
I am trying to get the data from firebase version9.8 in react.js project, but I am getting the error:
Uncaught (in promise) FirebaseError: Invalid document reference. Document references must have an even number of segments, but Users has 1.
how can I resolve this?
( I want to get the write the data in firebase on submit button so so i write the code in onSubmitHandler )
const onSubmitHandler = async (event) => {
console.log(event);
console.log("saving data to database request is Trigered...")
// Hear we push the data in firestore databae
await setDoc(doc(db, "Users",), {
name:collectionOfStates},{merge: true}
).then(() => console.log("Data Save in firebase")).catch((error) => {
console.log(error);
})
}
Upvotes: 0
Views: 1252
Reputation: 598807
Your code tries to write data into the Users
collection, instead of in a document under it, which is not possible.
If you want to write to a specific, known document, specify its document ID in the call to doc
:
// 👇
setDoc(doc(db, "Users", "idOfDoc"), {
name:collectionOfStates},{merge: true}
)
If you want to add a new document to the collection with an auto-generated ID, use addDoc
instead of setDoc
:
// 👇
addDoc(doc(db, "Users"), {
name:collectionOfStates},{merge: true}
)
Upvotes: 1