loading...

FieldValue.arrayUnion() called with invalid data. Nested arrays are not supported

wceolin profile image Will Ceolin ・1 min read

When trying to update an array in Cloud Firestore you might run into this error: FieldValue.arrayUnion() called with invalid data. Nested arrays are not supported.

However, that error might be a bit misleading. The following code will crash:

firebase.firestore.FieldValue.arrayUnion(['javascript', 'typescript']);

You don't have nested but your code will fail anyway because Firestore requires you to pass those items individually. All you have to do is using the spread operator instead:

firebase.firestore.FieldValue.arrayUnion(...['javascript', 'typescript']);

Discussion

pic
Editor guide