1

I want to add a nested array into Firestore but when I tried to Firestore gave the following error

Unhandled Exception: [cloud_firestore/unknown] Invalid data. Nested arrays are not supported

Here is JSON format which I want to to add to Firestore:

{
        "time": "7:00pm",
        "isSet": false,
        "leds": [
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 0],
            ]
    }

Here is a Model Class Which I was using for passing data

class LampModes {
  String name;
  int index;
  List<List<int>> leds;

  LampModes(this.name, this.index, this.leds);

}

Is there any way to add a nested array into Firebase Firestore?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Nikunj Ramani
  • 324
  • 1
  • 8

1 Answers1

3

Is there any way to add a nested array into firebase Firestore?

No, there is not. You cannot add arrays within an existing array type field. What you can do instead, is to create an object (map) that can hold arrays. So this document structure might solve your problem:

$docId
  |
  --- leds (map)
       |
       --- $someId: [0, 0, 0, 0]
       |
       --- $someId: [0, 0, 0, 0]

Then you can simply read the document, get the leds object (map), and iterate the content to get all arrays.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193