title: NodeJS + MongoDB: find() with specific conditions
body: <p>I have no ideas how to do this, so I need your advice. I have form with 4 checkboxes:</p>
  
  <pre><code>&lt;input type="checkbox" class="checkbox" id="check_stain"&gt;
  &lt;input type="checkbox" class="checkbox" id="check_black"&gt;
  &lt;input type="checkbox" class="checkbox" id="check_titan"&gt;
  &lt;input type="checkbox" class="checkbox" id="check_special"&gt;
  </code></pre>
  
  <p>I send data with simple submit, so if check_stain was checked, then req.body.check_stain will be "on", if not - "undefined". </p>
  
  <p>In my db I have collection "companies", with several objects, every of which contains such schema:</p>
  
  <pre><code>{...
      "stain": "false",
      "black": "true",
      "titan": "false",
      "special": "true",
  ...}
  </code></pre>
  
  <p>values are simple strings. So, I need to get every object for which specified checkboxes are true (on), but not including ones that nones (undefined). In other words, I'd like to create a simple search algorithm. Let me give you an example: we check check_stain and we should get every object where stain is "true". Maybe other values will be "true"/"false" (doesn't matter). If we select check_stain and check_black, we get object with stain &amp; black = "true", other fields are not interested.</p>
  
  <p>I always find with such code:</p>
  
  <pre><code>collection.find({ %my-condition% } ,function(err, companies) {
      companies.each(function(err, company){
          //do smth with found
      });
  });
  </code></pre>
  
  <p>But I have no idea how to write condition to find. I suppose, I should use $or operator in request. I read the docs, but I still can't get it. Thanks.</p>
  
  <p><strong>UPDATE: Huh, that seems to be a solution of my problem:</strong></p>
  
  <pre><code>if (req.body.sort_query == 'req-steel') {
  var condition = {}
  if (req.body.check_stain == "on") {condition['stain'] = 'true';}
  if (req.body.check_black == "on") {condition['black'] = 'true';}
  if (req.body.check_titan == "on") {condition['titan'] = 'true';}
  if (req.body.check_other == "on") {condition['special'] = 'true';}
  for (var i in condition) {
      if (condition[i] != "true") {
          delete condition[i];
      }
  }
  var companies_list = new Array();
  collection.find(condition, function (err, companies) {
      companies.each(function (err, company) {
          //do smth
      });
  });
  };
  </code></pre>