title: mongoose finding records with multiple conditions and checking if the request parameter not empty
body: <p>I'm new to this technology and working with Node and Express server that uses Mongoose and MongoDB 3.3 . I have following schema for a document collection.</p>
  
  <pre><code>exports.schemaLivre = new mongoose.Schema({
      Id : Number,
      Nom: { type: String, maxlength: 50 },
      Auteur: String,
      Description: String,
      Categorie: String,
  }
  exports.Livre = mongoose.model('Livre', schemas.schemaLivre);
  </code></pre>
  
  
  
  <p>I'm trying to run a web service having 3 parameters .</p>
  
  <pre><code>app.get('/Livres/search=:search&amp;category:=category&amp;auteur=:auteur', controller.RecupererLivresMultiple);
  </code></pre>
  
  <p>each parameter can be empty and foreach parameter I have a different kind of search logic ( for the param search , I will use regex expression to check through "Nom" and "Description" and "Auteur" fields in the same time, for category and auteur , the value submitted must be equal to the content of the field).
  I will need something like that but I didn't found the right query .</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>exports.RecupererLivresMultiple = function (req, res) {
      var re = new RegExp(req.params.search, 'i');
  
      models.Livre.find($and: [ 
          { 
              $or: [
                  { 'Auteur': req.params.auteur }, 
              ]
          },
          {
              $or: [ 
                  { 'Category': req.params.Category }, 
              ]
          }
      ]).or([{'Nom': {$regex: re}}, {'Auteur': {$regex: re}},{'Description':{$regex: re}}]).exec(function (err, livres) {
          if (err) {
              return console.error(err);
          }
          res.json(livres);
      });
  };
  </code></pre>
  
  <p>The question is How to check the request parameter sent from the web service is empty and How I disable it in my query when searching for records .
  My second question is how to combine those logic of search together ?</p>