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

wceolin

Will Ceolin

Posted on August 26, 2020

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

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']);
Enter fullscreen mode Exit fullscreen mode

You don't have a nested array per se but your code will fail 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']);
Enter fullscreen mode Exit fullscreen mode

Follow me on Twitter

💖 💪 🙅 🚩
wceolin
Will Ceolin

Posted on August 26, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related