Syntax for Azure Cosmos DB CONTAINS

amy8374 picture amy8374 · Mar 1, 2017 · Viewed 23k times · Source

I have the following JSON Store on Azure Cosmos DB.

{
  "id": "4",
  "total": 10.46,
  "tax": 0.55,
  "soldItems": [
    {
      "item": "CHEESE NIPS 004400001300 F 1.97 D",
      "price": 1.97
    },
    {
      "item": "ROOT BEER 10.46",
      "price": 10.46
    }
    ]
}

and I am getting no results from this query:

SELECT * from c where CONTAINS(c.soldItems.item, "BEER")

What would be the correct syntax to check for a string in an JSON object value?

Answer

Larry Maccherone picture Larry Maccherone · Mar 2, 2017

Try this:

SELECT VALUE c FROM c JOIN s in c.soldItems WHERE CONTAINS(s.item, "BEER")