title: Check if subdocument in range complies with a condition
body: <p>I'm working on a mongoDB query.</p>
  
  <p>I have several documents which I query with following results:</p>
  
  <pre><code>{
      "_id" : 1000.0,
      "date" : ISODate("2018-05-25T00:20:00.000Z"),
      "value" : true
  }
  
  {
      "_id" : 1000.0,
      "date" : ISODate("2018-05-25T00:26:00.000Z"),
      "value" : false
  }
  
  {
      "_id" : 1000.0,
      "date" : ISODate("2018-05-25T00:30:00.000Z"),
      "value" : false
  }
  </code></pre>
  
  <p>The original documents are filtered so that I get only document within the last 15 minutes before <em>now</em> and there is no way of knowing how many entries are in that time range.</p>
  
  <p>I need to expand my existing query so that it returns a status based on the "value". If there are <em>no true</em> I need a status <em>0</em>, if there is <em>at least 1 but not only true</em> I need a status <em>1</em>, and if there are <em>only true</em> I need a status 2.</p>
  
  <p>For example:</p>
  
  <pre><code>{
      "_id" : 1000,
      "status" : 1
  },
  {
      "_id" : 1001,
      "status" : 2
  }
  </code></pre>
  
  <p>Is there a way of accomplishing this using mongoDB? Or would it be better/easier to do it on java side? Note that there are several _id in the database.</p>