2017-12-18 248 views
0

我有2個對象DocumentDB像下面,查詢在DocumentDB基於JSON的內在價值 - C#

{ 
    "TrackGoods": { 
     "Attributes": { 
      "Attribute": { 
       "BlockName": "Default", 
       "Brand": "Default", 
       "CaseType": "Carton", 
      } 
     }, 
     "Codes": [{ 
      "trackcode": "191155772333RIF1" 
     }, 
     { 
      "trackcode": "721141315199RIF2" 
     }], 
     "Time": "2017-12-18T13:35:04.0792480+05:30", 
     "IpAddress": "127.0.0.1", 
     "Lat": "155.00", 
     "Long": "-202.00", 
    } 
} 

{ 
    "TrackGoods": { 
     "Attributes": { 
      "Attribute": { 
       "BlockName": "Default1", 
       "Brand": "Default1", 
       "CaseType": "Carton1", 
      } 
     }, 
     "Codes": [{ 
      "trackcode": "191155772333RIF3" 
     }, 
     { 
      "trackcode": "721141315199RIF4" 
     }], 
     "Time": "2017-12-18T13:35:04.0792480+05:30", 
     "IpAddress": "127.0.0.1", 
     "Lat": "155.00", 
     "Long": "-202.00", 
    } 
} 

我想要得到的文件,其中有一個trackcode碼=「191155772333RIF1」。

我嘗試以下查詢,它不會從DocDB返回文檔,

string selectdoc = "select doc.TrackGoods from doc join Codes in doc.Codes where Codes.trackcode = '191155772333RIF1'"; 
    query = new SqlQuerySpec(selectdoc, 
     new SqlParameterCollection(new SqlParameter[] { 
      new SqlParameter { Name = "@code", Value = code } 
      })); 

任何一個可以幫助我擺脫DocDB文檔。

感謝

回答

1

我試着用此查詢,它似乎正常工作:

select doc.TrackGoods from doc join Codes in doc.TrackGoods.Codes where Codes.trackcode = '191155772333RIF1'

你在in後失蹤的.TrackGoods.

有關JOIN的更多信息,請查看this article