0

I have this very simple test document stored in DocumentDb:

{
  "DocumentDbTest_Countries": {
      "@country": "C24105130563",
      "@language": "C24105130563",
      "@countryCode": 1663405662,
      "@version": "2015-08-24T08:51:32:030.6165"
  },
  "id": "729607bd-38c5-2a96-0bc4-371a0a5bca4a"
}

Which I can find easily using the Document Explorer, and, also using the following Sql query in the Query Explorer:

SELECT * FROM DocumentDbTest_Countries c

But surprisingly when i run the following SQL query, it can't find the result:

SELECT * FROM DocumentDbTest_Countries c where c.country = 'C24105130563'

Can someone please guide me as to what I am doing wrong in the above SQL query?? I tried using double quotes instead of single but to no avail.

2 Answers 2

1

Since @ is a special character, you have to escape it with the Dictionary-like [] operator. For example, run the query as:

SELECT * FROM DocumentDbTest_Countries c where c["@country"] = 'C24105130563'
Sign up to request clarification or add additional context in comments.

Comments

0

Found it. Its because of the @ sign present in the attributes.

Strangely I am using DocumentDB SDK to insert the data and those @ signs in the attributes are inserted by it. :(

Now have to find a way to remove the @ sign from the inserts.

3 Comments

Can you please post the code sample with the DocumentDB SDK?
Sure @AravindRamachandran I was trying to convert the following xml to JSON and save it to DocumentDB: <DocumentDbTest.Countries country="C25103657983" language="C25103657983" countryCode="383388823" version="2015-08-25T08:36:59:982.3552" /> Now the Newtonsoft.Json.JsonConvert.SerializeXmlNode adds the @ to the attributes by default, which gets saved as it to the DocumentDB without any issues/warnings. But then you can't search on it afterwards. :(
Got it, please see how to escape the @ character in queries below.

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.