Firebase-js-sdk: FR: support nested arrays in firestore, just like in admin-node-sdk

Created on 8 Oct 2017  路  17Comments  路  Source: firebase/firebase-js-sdk

Describe your environment

  • Operating System version: Mac OS 10.13
  • Firebase SDK version: 4.5.0
  • Firebase Product: firestore

Describe the problem

When saving a field of array type, where each array's item is an object with some array fields/properties, the error is thrown "DocumentReference.set() called with invalid data. Nested arrays are not supported". But admin-node-sdk allows to write such data and in the firestore console, nested arrays are properly shown (although you cannot add nested array).

Steps to reproduce:

doc(..).set({arrayField: [
 {someArrayProperty: [
   {someField: ["test", "test"]}
  ]},
 {someArrayProperty: [
   {someField: ["test", "test"]}
  ]}
]})

Most helpful comment

I apologize for not knowing the difference, can someone post an example of directly nested vs indirectly nested arrays?

Is it meant to mean "arrays directly nested in arrays" and "arrays indirectly nested in arrays"?

Directly?

{
  "arrayOfArrays": [
    [ 1, 2, 3, 4 ],
    [ "a", "b", "c", "d" ]
  ]
}

Indirectly?

{
  "arrayOfObjectsOfArrays": [
   { "contents": [ 1, 2, 3, 4 ] },
   { "contents": [ "a", "b", "c", "d" ] }
  ]
}

All 17 comments

+1

+1

Pretty serious issue...

+984721

The 4.6.0 release that went out today includes pull https://github.com/firebase/firebase-js-sdk/pull/228 which addresses this.

Note that directly nested arrays are still unsupported (and are a backend restriction).

@wilhuff great! Thanks

@wilhuff Fantastic. Thanks.

@wilhuff thx:)

I apologize for not knowing the difference, can someone post an example of directly nested vs indirectly nested arrays?

Is it meant to mean "arrays directly nested in arrays" and "arrays indirectly nested in arrays"?

Directly?

{
  "arrayOfArrays": [
    [ 1, 2, 3, 4 ],
    [ "a", "b", "c", "d" ]
  ]
}

Indirectly?

{
  "arrayOfObjectsOfArrays": [
   { "contents": [ 1, 2, 3, 4 ] },
   { "contents": [ "a", "b", "c", "d" ] }
  ]
}

Your examples describe this perfectly.

Same here..

@jaonoctus I don't understand your comment.

Release 4.6.0 fixed indirectly nested arrays (i.e. arrays can contain objects can contain arrays).

Directly nested arrays (i.e. arrays directly containing other arrays) are unsupported and there aren't any plans to do so given backend limitations.

When you say "Same here" are you

  • saying that indirectly nested arrays aren't working for you even after release 4.6.0?
  • expressing interest in directly nested arrays?

The former would be a serious regression we need to look into. The latter I can't really help with given the complexity of removing the limitation.

@wilhuff First of all, thank you for your time.

Let me try to explain:

I'm using Firestore Beta Database and i have this structure in a document:

{
    "array": [
        { "website": "url-here" },
        { "website": "url-here" }
    ]
}

And i'm trying to write a Firebase Function to fetch data about that websites in this array and merge the new informations.

The issue is: after the first update by the function, I tried to add a new object in the array on console.firebase.com and the message "unable to save field" appeared.

Trying to add from Firestore Database UI:

  {
    test: [
      {
        test2: [ 
           { 
             test3: "test4" 
           }
        ]
      }
    ]
  }

Results in Unable to save field.

@Modestas Thanks for the report. I've pinged the folks who work on the console UI to see if we can get this resolved. In the meantime you may have to do that write manually via the SDK. Sorry for the inconvenience!

Will support for directly nested arrays ever come or was the hint that its a backend restriction basicly saying that it will never come?

Is this somewhere mentioned within the documentation? I have just found out about it by running into this error after already building parts of the UI with directly nested arrays 馃槚

@jaschaio It's in the docs: https://firebase.google.com/docs/firestore/manage-data/data-types#data_types

Also, at some point in the future yes we'll be able to support nested arrays - but it's not going to happen anytime soon. Sorry I can't be more specific, but I won't bank on directly nesting arrays for any apps you're building at the moment.

Was this page helpful?
0 / 5 - 0 ratings