0

I'm working with Firestore. The following code updates the matrix with a single element, that is, each time a user executes that function, said field is updated:

updateFavoritos(key) {
    const user = firebase.auth().currentUser;
    this.afs.doc('eventos/' + key).update({
      favoritos: [ user.uid ],
    });
  }

This looks like this: enter image description here

But how can I do to add instead of updating that matrix, is to say something like this:

enter image description here

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
Paco Zevallos
  • 2,027
  • 7
  • 25
  • 59

1 Answers1

0

Firestore have methods to handle arrays. Link to the docs

var washingtonRef = db.collection("cities").doc("DC");

// Atomically add a new region to the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});

// Atomically remove a region from the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayRemove("east_coast")
});
Marco
  • 2,549
  • 20
  • 24