title: How to compare two object elements in a mongodb array
body: <pre><code>{
    &quot;customerSchemes&quot;: [
      {
        &quot;name&quot;: &quot;A&quot;,
        &quot;startDate&quot;: some date in valid date format
      },
      {
        &quot;name&quot;: &quot;B&quot;,
        &quot;startDate&quot;: some date in valid date format.
      }
    ]
  }
  </code></pre>
  <p>I am trying to figure out all documents where scheme A started before scheme B.
  Please note that the scheme Array is not in ascending order of startDate. Plan B can have an earlier date as compared to plan A.
  I believe unwind operator could be of some use here but not sure how to progress with next steps.</p>