0

I have 2 objects in DocumentDB like below,

{
    "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",
    }
}

I want to get the document where a Codes with trackcode='191155772333RIF1'.

I tried the following query and it is not returning the document from 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 }
          })); 

Can any one help me to get the document from DocDB.

Thanks

1 Answer 1

1

I tried with this query and it seemed to work correctly:

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

You were missing the .TrackGoods. in after the in.

For more information regarding JOIN, take a look at this article.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.