Couchbase Lite 2.0 – “Fleece encode/decode error” while putting a document that contains nested arrays

Hi,

I want to put a document similar to the following.

{
  "key_1": [
    {
      "key_2": [
        {
          "key_3": [
            {
              "key_4": [
                {
                  "key_5": [
                    {
                      "key_6": "value"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "_rev": "1-37878bf6becb76fbebd441aaa7cbd732",
  "_id": "test_document"
}

I successfully put it by using Couchbase Lite 1.4 in my Xamarin Android and Xamarin iOS projects.

However when I try to put a document by using 2.0 development build in my UWP project, I get “LiteCoreException (4): Fleece encode/decode error” exception while saving document to database.

When the count of nested arrays is less than 6 it works fine but if it is equal or more than 6 I get exception.

My code for putting document is below.

...
var props = CreateNestedProperties(1, 6);
document.Set(props);
database.Save(document); // Exception
...

private Dictionary<string, object> CreateNestedProperties(int index, int count)
{
    var dict = new Dictionary<string, object>();
    if (index < count)
    {
        dict.Add("key_" + index, new Dictionary<string, object>[1]
        {
            CreateNestedProperties(index + 1, count)
        });
    }
    else
    {
        dict.Add("key_" + index, "value");
    }
    return dict;
}

I wrote this code just for demonstrating the issue, the document will be more complex and arrays will have more than one element.

Thanks.

There’s no limit on nesting, and I don’t know C# well, but your code looks fine. Could you file a bug report against couchase-lite-net on Github, please?

@borrrden pointed out to me that there actually is a limit of 10 levels of nesting in the encoder. We can increase that (and possibly make it growable), but I’m curious what the practical reason is why you need 12 or more levels of nesting in your documents?

We are planning to store documents that will keep information of question-answer forms, in the database. And the questions may have some sub-questions, and these sub-questions may also have some sub-questions and so on. It is unpredictable for us what the number of nested questions will be but these forms will be kind of complex and probably we will need many.

I’ve filed an issue to remove fixed limits on nesting depth. Thanks for pointing this out — it’s in code I wrote early on and I’d forgotten completely that this limit exists.