2

I have Database like this enter image description here

now I need to push items to directors array.

I tried this code

Firestore()
    .collection('notices')
    .doc(item.id)
    .set({readBy: {directors: [user.id]}}, {merge: true});

but it replace the existing items in directors array.

How to push items to directors array without replacing existing items ?

1 Answers1

1

You need to use the arrayUnion function for this:

Firestore()
.collection('notices')
.doc(item.id)
.set({readBy: {directors: FieldValue.arrayUnion([user.id])}}, {merge: true});
l1b3rty
  • 3,333
  • 14
  • 32