How do Unnesting Dictionary Type?

n1ql

#1

hello.
i have a problem!

first example.
{
  "id":"A",
  "itemlist":{
     {
        "itemunique":55,
        "itemtype":1,
        "count":5
     },
     {
        "itemunique":56,
        "itemtype":2,
        "count":5
     },
   }
}

select a.* from [Bucket] unnest itemlist a where a.itemtype = 1;
it’s able.

second example.
{
  "id":"A",
  "itemdic":{
     {
        55:{
            "itemtype":1,
            "count":5
         },
       56:{
            "itemtype":2,
            "count":5
         },
   }
}

select a.* from [Bucket] unnest itemdic a where a.itemtype = 1;
it’s impossible!! ToT

error message:
    "errors": [
        {
            "code": 3000,
            "msg": "Ambiguous reference to field itemtype."
        }

how can i fix it??
dictionary type is necessary. please help me…


#2

Hi @prym,
looks like your doc is not well formed.
I guess ‘itemlist’ in first example is an array, i.e should use [] instead of {}.
Similarly, ‘itemdic’ in your second example should be an array of objects, and for each object, the keys 55, 56 etc should be in double quotes.

-Prasad


#3

Hello @prasad.

i'm using Newtonsoft.Json in c# code.
this type is "Dictionary<int, object>".

only available for "List<object>" type?

#4

Hi @prym,

Can you first get this working in cbq shell or Query Workbench, before going back to your c# code.