title: mongoDB is there any way for aggregate $gte to not show the false data
body: <p><a href="https://docs.mongodb.com/manual/reference/operator/aggregation/gte/" rel="nofollow">https://docs.mongodb.com/manual/reference/operator/aggregation/gte/</a></p>
  
  <p>As you can see in the above mongo db documentation, $gte returns the data which is false too.</p>
  
  <p>Example json data:</p>
  
  <pre><code>{ "_id" : 1, "item" : "abc1", description: "product 1", qty: 300 }
  { "_id" : 2, "item" : "abc2", description: "product 2", qty: 200 }
  { "_id" : 3, "item" : "xyz1", description: "product 3", qty: 250 }
  { "_id" : 4, "item" : "VWZ1", description: "product 4", qty: 300 }
  { "_id" : 5, "item" : "VWZ2", description: "product 5", qty: 180 }
  </code></pre>
  
  <p>Query for getting the data where qty is greater than 250:</p>
  
  <pre><code>db.inventory.aggregate(
     [
       {
         $project:
            {
              item: 1,
              qty: 1,
              qtyGte250: { $gte: [ "$qty", 250 ] },
              _id: 0
            }
       }
     ]
  )
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{ "item" : "abc1", "qty" : 300, "qtyGte250" : true }
  { "item" : "abc2", "qty" : 200, "qtyGte250" : false }
  { "item" : "xyz1", "qty" : 250, "qtyGte250" : true }
  { "item" : "VWZ1", "qty" : 300, "qtyGte250" : true }
  { "item" : "VWZ2", "qty" : 180, "qtyGte250" : false }
  </code></pre>
  
  <p><strong>Problem:</strong>
  Well I want data where qty > 250, but mongo db shows all data, and thus when records are so high in number the site becomes so slow.</p>
  
  <p>I am using ruby on rails with mongoid, and I have some query where I need to use group by clause, so I have to aggregate, but this is return all data.
  My original Query:</p>
  
  <pre><code>data = SomeModel.collection.aggregate([
        {"$project" =&gt; {
          "dayOfMonth" =&gt; {"$dayOfMonth" =&gt; "$created_time"},
          "month" =&gt; {"$month" =&gt; "$created_time"},
          "year" =&gt; {"$year" =&gt; "$created_time"},
          "date_check_gte" =&gt; {"$gte" =&gt; ["$created_time",start_time]},
          "date_check_lte" =&gt; {"$lte" =&gt; ["$created_time",end_time]},
        }},
        {"$group" =&gt; {
          "_id" =&gt; { "dayOfMonth" =&gt; "$dayOfMonth", "month" =&gt; "$month", "year" =&gt; "$year"},
          "Total" =&gt; {"$sum" =&gt; 1},
          "check_one" =&gt; {"$first" =&gt; "$date_check_gte"},
          "check_two" =&gt; {"$first" =&gt; "$date_check_lte"}
        }},
        {"$sort" =&gt; {
          "Total" =&gt; 1
        }}
      ])
  </code></pre>
  
  <p>Groups perfectly but returns all data despite the use of gte and lte.
  Is there anything that can be done so that false data don't show up ?</p>