2017-01-11 226 views
1

我無法查詢DocumentDB中的嵌套對象。我無法控制數據的格式。比方說,一個物體看起來像這樣在DocumentDB:DocumentDB查詢嵌套對象

{ 
    "SCHEMA_ID": { 
     "PROJECT": "A", 
     "MODEL": "B", 
     "GUID":"A GUID" 
    }, 
    "STATE": { 
     "Active": "True" 
    }, 
    "OBJECTS": { 
     "OBJECT": [ 
      { 
       "ATTR_VALS": { 
        "NAME": "Header", 
        "ID": "0", 
        "VALUE": [ 
         { 
          "NAME": "JobId", 
          "VAL": "1011656" 
         }, 
         { 
          "NAM": "Region", 
          "VAL": "West Coast" 
         } 
        ] 
       } 
      }, 
      { 
       "ATTR_VALS": { 
        "NAME": "SampleData", 
        "ID": "0", 
        "VALUE": [ 
         { 
          "NAME": "Height", 
          "VAL": "5" 
         }, 
         { 
          "NAM": "Length", 
          "VAL": "3" 
         } 
        ] 
       } 
      } 
     ] 
    } 
} 

我想找到所有有「ATTR_VALS」 =「的sampleData」,畫在那裏這些項目有一個「高」 = 5

所以遠我有:

SELECT test.GUID 
FROM test 
join OBJECTS in test.OBJECTS 
join OBJECT in OBJECTS 
join ATTR_VALS in OBJECT 
join VALUE in ATTR_VALS 
WHERE ATTR_VALS.NAME = 'SampleData' AND VALUE.NAME='Height' AND VALUE.VAL='5' 

但是這不起作用,並且不會返回任何結果。謝謝!

+0

你得到的結果投影子句中必須進行轉義

  • 小錯字,當你點擊「下一頁」?某些查詢可能不會返回第一頁中的結果,但會在後續頁面中返回結果。 –

  • +0

    @AravindRamachandran我得到0個結果。我在.net代碼中運行查詢。沒有連接的類似代碼返回數據正常(如SELECT * FROM test WHERE test.GUID ='GUID') – Jeremy

    回答

    2

    查詢必須是:

    SELECT test.SCHEMA_ID.GUID 
    FROM test 
    join OBJ in test.OBJECTS.OBJECT 
    join VAL in OBJ.ATTR_VALS["VALUE"] 
    WHERE OBJ.ATTR_VALS.NAME = "SampleData" AND VAL.NAME='Height' AND VAL.VAL='5' 
    

    一對夫婦的事情,我改變了:

    • JOIN必須對數組,而不是對象進行。對象可以使用「」操作員
    • 值是一個特殊的關鍵字進行擴展和失蹤SCHEMA_ID