title: How to create dynamic search in mongoose
body: <p>I want to create a dynamic search in mongoose from (get the URL in the request).</p>
  
  <p>Here is sample of my url
  <a href="http://www.localhost:3000/listing?&amp;colour=blue&amp;gender=women" rel="nofollow noreferrer">http://www.localhost:3000/listing?&amp;colour=blue&amp;gender=women</a></p>
  
  <p>User able to select multiple colour and gender so that the url can like
  <a href="http://www.localhost:3000/listing?&amp;colour=blue&amp;gender=women&amp;colour=red&amp;gender=men" rel="nofollow noreferrer">http://www.localhost:3000/listing?&amp;colour=blue&amp;gender=women&amp;colour=red&amp;gender=men</a></p>
  
  <p>I have 3 query record in my mongodb with data like</p>
  
  <p>1)    gender : 'male',
        colour  :  'red'</p>
  
  <p>2)   gender : 'women',
       colour  : 'blue'</p>
  
  <p>3)   gender : 'women',
       colour  : 'blue'</p>
  
  <pre><code>var productSchema = new Schema ({
          price: String,
          gender: String,
          colour: String,
          item: [{
              name: String,
              slug: String,
              sku: String,
              size : String,
              stock: String,
          }],
          attributes: {
              waterProof : String,
              warranty : String,
              caseMaterial : String,
              movement : String,
              lens : String,
              bandMaterial : String,
              options : String,
              typeOfMovement : String,
          }
      });
  
  var arrayGet = req.query;
  var generateQuery ="{";
  for (var k in arrayGet){
  if (arrayGet.hasOwnProperty(k)) {
     if(k =='gender'){
       var    gender = arrayGet[k];
     }else if(k =='colour'){
       var    colour = arrayGet[k];
     }
  }
  
  if (typeof gender !== 'undefined'){
      generateQuery += '{gender : { $in: gender },';
  }
  if (typeof colour !== 'undefined') {
      generateQuery += '{price : { $in: colour }';
  }
  
  generateQuery +="}";
  
  // i get 3 query from mongoDB which is wrong
  Product.find(generateQuery, function(err, result) {
     console.log(result);
  })
  
  //i get 2 query from mongoDB which is correct
  Product.find({gender : { $in: gender },colour : { $in: colour }},function(err,result){
      console.log(result);
  })
  </code></pre>
  
  <p>May i know where i did wrong</p>