DEV Community

Will Ceolin
Will Ceolin

Posted on • Updated on

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

Latest comments (7)

Collapse
 
kinetic9 profile image
Bongani

Thanks

Collapse
 
mugii profile image
MUGII

thanks, it's working

Collapse
 
crowdozer profile image
crowdozer

!!

what a misleading error message, you just saved me a headache and a rewrite.

Collapse
 
tidianeb5 profile image
tidianeb5

thanks . 😊

Collapse
 
eghubs profile image
EgHubs

You saved my day! Thank you!

Collapse
 
janajunkiss profile image
JanaJunkiss

You saved my day! Thank you!

Collapse
 
pranavsarda profile image
Pranav Sarda

Really helpful post....was searching for "Adding an array into a Firebase Array Field.", with no luck. Finally, found a proper verified no for direct use of arrayUnion. Thanks a lot man.