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?

2
  • could you please include the way you try so far? Commented Sep 4, 2022 at 6:30
  • "Is there any way to add a nested array into firebase firestore?" No, as the error explains. also checkout: stackoverflow.com/q/62094696/13130697 Commented Sep 4, 2022 at 6:40

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey Alex. thanks for the answer for now we have changed data formats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.