Paul Baiju
Paul Baiju

Reputation: 419

How can i enter multiple data into documents in FIRESTORE

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

Answers (1)

Hareesh
Hareesh

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

Related Questions