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

2

1 Answer 1

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")
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.