DocumentDB SQL with ARRAY_CONTAINS
<p>I'm playing around on <a href="https://www.documentdb.com/sql/demo" rel="noreferrer">https://www.documentdb.com/sql/demo</a>, which allows me to query against sample documents that look like:</p>

<pre><code>{
  "id": "19015",
  "description": "Snacks, granola bars, hard, plain",
  "tags": [
    {
      "name": "snacks"
    }
  ],
  "version": 1,
  "isFromSurvey": false,
  "foodGroup": "Snacks",
  "servings": [
    {
      "amount": 1,
      "description": "bar",
      "weightInGrams": 21
    }
  ]
}
</code></pre>

<p>I'm confused about <code>ARRAY_CONTAINS()</code>. This query returns results:</p>

<pre><code>SELECT root
FROM root 
WHERE ARRAY_CONTAINS(root.tags, { "name": "snacks" })
</code></pre>

<p>However, this query does not:</p>

<pre><code>SELECT root
FROM root 
WHERE ARRAY_CONTAINS(root.servings, { "description": "bar" })
</code></pre>

<p>What gives?</p>

<p>What I'm trying to achieve is illustrated by how I would write the query if this was C#:</p>

<pre><code>var filteredDocs = docs.Where(d =&gt; d.Servings != null &amp;&amp;
                                   d.Servings.Length &gt; 0 &amp;&amp;
                                   d.Servings.Any(s =&gt; s.Description == "bar"));
</code></pre>

<p>It appears the first example query on <code>root.tags</code> works because <code>{ "name": "snacks" }</code> is the <em>entire</em> object in the <code>root.tags</code> array, while, in the second query, <code>{ "description": "bar" }</code> is only <em>one field</em> in the <code>root.servings</code> objects. </p>

<p>How can I modify the second query on <code>root.servings</code> to work with only knowing the serving <code>description</code>?</p>