code for uploading data in firestore
Console: "Document written with ID: undefined"
try {
console.log
const docRef = addDoc(collection(db, "users"), {
name: "Alan",
//middle: "Mathison",
//last: "Turing",
//born: 1912
});
console.log('yyyyy');
console.log("Document written with ID: ", docRef.id);
} catch (e) {
console.error("Error adding document: ", e);
}
Trying to add data in Firebase Firestore,
2
Answers
addDoc
is an asynchronous operation. You need to use theawait
keyword to halt execution of your code until the document is added. OtherwisedocRef
will not represent your document.try that