title: updating a document using the $max operator on arrays
body: <p>i have the following document:</p>
  <pre><code> {
      _id: 12,
      item: 'envelope',
      qty: ISODate(&quot;2021-12-05T00:00:00.000Z&quot;),
      arrayField: [ 128, 190, 1 ]
    }
  </code></pre>
  <p>and i try to update it using this command</p>
  <pre><code>products&gt; db.products.update({_id:12},{$max : { arrayField : [1,190,1879]} })
  </code></pre>
  <p>the output is as follows:</p>
  <pre><code>{
    acknowledged: true,
    insertedId: null,
    matchedCount: 1,
    modifiedCount: 0,
    upsertedCount: 0
  }
  </code></pre>
  <p>I don't really understand how the comparison between the existing arrayField and the new one is being done. They are both Arrays, so there should be some kind of comparison on every element, but how exactly does it work?</p>
  <p>From the <a href="https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#std-label-faq-dev-compare-order-for-BSON-types" rel="nofollow noreferrer">documentation</a> i read this:</p>
  <blockquote>
  <p>With arrays, a less-than comparison or an ascending sort compares the smallest element of arrays, and a greater-than comparison or a descending sort compares the largest element of the arrays. As such, when comparing a field whose value is a single-element array (e.g. <a href="https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#std-label-faq-dev-compare-order-for-BSON-types" rel="nofollow noreferrer"> 1 </a>) with non-array fields (e.g. 2), the comparison is between 1 and 2. A comparison of an empty array (e.g. [ ]) treats the empty array as less than null or a missing field.</p>
  </blockquote>
  <p>But i still don't understand exactly... Could someone provide an example in my case?
  Thanks in advance</p>