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
  • 565,676
  • 79
  • 828
  • 807
Paco Zevallos
  • 2,165
  • 7
  • 30
  • 68

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,757
  • 1
  • 19
  • 24