基于内部json值在DocumentDB中查询 - C#

问题描述 投票:0回答:1

我在DocumentDB中有2个对象,如下所示,

{
    "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获取文档。

谢谢

c# azure c#-4.0 azure-cosmosdb
1个回答
1
投票

我试过这个查询,它似乎工作正常:

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

.TrackGoods.之后你错过了in

有关JOIN的更多信息,请查看this article

© www.soinside.com 2019 - 2024. All rights reserved.