2

If I add the same data inside the same array in Firestore, it not creates more indexes in the array because it has the same data.

I want it to create more indexed when the same data is entered inside the array.

for example:

enter image description here

expected result:

expected result

code:

// collection reference
const collectionRef = collection(db, 'exercises data');
// submit function to add the exercises data
const handleSubmit = async (e) => {
    e.preventDefault();
    const usr = auth.currentUser;
    await setDoc(doc(collectionRef, usr.uid), {
        exercise: arrayUnion(exercise),
        sets: arrayUnion(Number(sets)),
        reps: arrayUnion(Number(reps)),
    }, { merge: true })
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ashka
  • 83
  • 4
  • 1
    `arrayUnion()` adds data only if it is not present in the array already. If you want to add duplicate values then you'll have to read, modify and update the entire array back as in the linked answers. – Dharmaraj Oct 24 '22 at 08:02

0 Answers0