0

Hey i am make a schedule component in Angular and where i have a form that the user fills out ->

Model:_____ StartDate: _____ QTY: ______

Now, I would like it to be stores in that each one is its own record: For example, if i put quantity as 5, it will have 5 records (this way i can make each unit complete). What I have so far is below:

for (let counter = 1; counter < Qty + 1; Counter++)
    {
        db.collection("sched").add({
        Model: "FakeModel",
        StartDate: "06-06-2020",
        UnitNumber: counter,
        complete: false
    });
}

There seems like there should be a better way?

Thanks in advance!

balance85
  • 39
  • 3
  • Use a batch. https://firebase.google.com/docs/firestore/manage-data/transactions#batched-writes – l1b3rty Jun 10 '20 at 22:18
  • How are you thinking this would be easier? Adding N documents requires creating N document references for use with `add()` or `set()`. There is no shortcut here. You can use a batch, but you still have to create N references with data to add to the batch. There are no "bulk create" options. – Doug Stevenson Jun 10 '20 at 22:24
  • I'm not thinking it would be easier, as that is relatively easy, just seemed like a 'scabby' way to do it. – balance85 Jun 10 '20 at 22:54
  • Unless you can be specific about what is scabby about it, it'll be hard to help. To me this looks like a normal way to create documents, and I don't think a batch is pertinently better (also see https://stackoverflow.com/questions/58897274/what-is-the-fastest-way-to-write-a-lot-of-documents-to-firestore). – Frank van Puffelen Jun 11 '20 at 04:20

0 Answers0