title: How to group query according to boolean field and retrieve all records separately by boolean value in MongoDB?
body: <p>The following are some insert statements </p>
  
  <pre><code>db.users.insert({ courseId: 1, stDt: new Date(2014, 01, 01), endDt: new Date(2014, 01, 20), active: false }); 
  db.users.insert({ courseId: 1, stDt: new Date(2014, 01, 25), endDt: new Date(2014, 02, 10), active: false }); 
  db.users.insert({ courseId: 1, stDt: new Date(2014, 02, 25), endDt: new Date(2014, 03, 10), active: true }); 
  db.users.insert({ courseId: 1, stDt: new Date(2014, 02, 28), endDt: new Date(2014, 06, 10), active: true }); 
  db.users.insert({ courseId: 1, stDt: new Date(2014, 02, 25), endDt: new Date(2014, 02, 30), active: false }); 
  db.users.insert({ courseId: 1, stDt: new Date(2014, 05, 25), endDt: new Date(2014, 10, 30), active: false }); 
  db.users.insert({ courseId: 1, stDt: new Date(2013, 10, 01), endDt: new Date(2014, 08, 10), active: true }); 
  db.users.insert({ courseId: 1, stDt: new Date(2014, 09, 01), endDt: new Date(2014, 11, 30), active: false }); 
  </code></pre>
  
  <p>Case 1: 
  Can we create following resultset from above inserted values? 
  Here all results with "active" field to true and false are sorted by "endDt" field retrieved seperately with single query. </p>
  
  <pre><code>{ "result" : { 
      true : [ 
        { endDt: new Date(2014, 03, 10), active: true }, 
        { endDt: new Date(2014, 06, 10), active: true },  
        { endDt: new Date(2014, 08, 10), active: true }, 
     ],
     false: [ 
        { endDt: new Date(2014, 01, 20), active: false }, 
        { endDt: new Date(2014, 02, 10), active: false }, 
        { endDt: new Date(2014, 02, 30), active: false }, 
        { endDt: new Date(2014, 10, 30), active: false }, 
        { endDt: new Date(2014, 11, 30), active: false } 
     ]
    }
  } 
  </code></pre>
  
  <p>Is it possible do it by single query? </p>
  
  <p>Case 2: 
  Can we do as following resultset? </p>
  
  <pre><code>{ "result" : [ 
      { endDt: new Date(2014, 01, 20), active: false }, 
      { endDt: new Date(2014, 02, 10), active: false }, 
      { endDt: new Date(2014, 02, 30), active: false }, 
      [   
          { endDt: new Date(2014, 03, 10), active: true }, 
          { endDt: new Date(2014, 06, 10), active: true },    
          { endDt: new Date(2014, 08, 10), active: true } 
      ], 
      { endDt: new Date(2014, 10, 30), active: false }, 
      { endDt: new Date(2014, 11, 30), active: false } 
    ]
  } 
  </code></pre>
  
  <p>Here sorted by <code>endDt</code> field, but last <code>endDt</code> record of <code>active</code> field true will have array with all previous "active" field true records in it. </p>
  
  <p>I think, second case is not possible. </p>