Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Functions ERROR: cannot convert an array value in an array value [closed]

I am trying to pass in the following 2d array of data into a field of a document using Cloud Functions.

[ [ '-LXRXPFgA6sC9Mg0GQMt', 1, 'Sushi premium' ], [ '-LXRSAp3jpB8EUbZU-0c', 1, 'Caramel Glazed Donuts' ] ]

The error I got is:

>Error: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
    at Object.exports.createStatusError (/user_code/node_modules/firebase-admin/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:1204:28)
    at InterceptingListener._callNext (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:845:24)
like image 908
Mozes Ong Avatar asked Feb 20 '19 11:02

Mozes Ong


1 Answers

Nested arrays are not supported in Cloud Firestore. You can store arrays of objects, and those objects can have fields that are arrays, but multi-level arrays are not possible.

You would need to change your data to look something more like:

[
  {"id": "-LXRXPFgA6sC9Mg0GQMt","number":1,"label":"Sushi premium"},
  // ...
]
like image 163
Michael Bleigh Avatar answered Nov 05 '22 03:11

Michael Bleigh