The signature of the arrayUnion
method looks like this: firebaseFirestore.FieldValue.arrayUnion(...elements: any[])
. This means it is expecting an argument list of elements that should go inside the array. But when you provide an array, that array is interpreted as one argument which would lead to the following: ['old-user', ['sarah', 'simon', 'lena']]
. This is of course not what we want and it obviously leads to the exception because an array as an element of another array is not supported by Firestore.
Therefore, the solution is just to convert the addedMemberIds
array to an argument list like so:
const addedMemberIds = ['sarah', 'simon', 'lena'];
doc.ref.update({
memberIds: FieldValue.arrayUnion(...addedMemberIds)
});