Reputation: 419
Currently when i enter a new value the old one gets overwritten ,i need to store all the entered values without overwriting. I am a beginner at this. thanks for the help.
const docRef = firestore.collection("samples").doc("itemData")
const outputHeader = document.querySelector("#productList");
const inputTextField = document.querySelector("#item");
const saveButton = document.querySelector("#saveButton");
saveButton.addEventListener("click",function() {
const textToSave = inputTextField.value;
docRef.set({
product: textToSave
}).then(function(){
console.log("status saved!");
}).catch(function(error){
console.log("got an error",error);
})
})
Upvotes: 0
Views: 709
Reputation: 6900
Set your ref to the samples collection
const docRef = firestore.collection("samples");
Now in the button click code
docRef.add({
product: textToSave,
cost: costToSave
}).then(function(){
console.log("status saved!");
}).catch(function(error){
console.log("got an error",error);
})
this will create documents under samples collection with a unique key.
Upvotes: 2