2017-12-18 142 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