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 ?

2

1 Answer 1

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});
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.