title: How do you pass multiple parameters from the client through NodeJS to MongoDB?
body: <p>Scenario:
  I want to have a searchbox that takes well-formed MongoDB db.collection.find() parameters in the same form as the MongoDB console, and will display the result on the webpage. </p>
  
  <p>I have already the logic that works when it comes to a parameter, that I know. Eg. getting document by ID:</p>
  
  <pre><code>var query = {};
  var selector = "id";
  query[selector] = Number(id);
  collection.find(
      query, {},
      function(e, docs) {
          if (e) { ... }
          if (docs != null &amp;&amp; docs.length != 0) {
              res.json(docs);
          } else { ... }
      });
  </code></pre>
  
  <p>However, what to do if I want to have multiple parameters that I don't know beforehand on the bakcend? </p>
  
  <p>What to look out for when sending the client GET request?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong>: </p>
  
  <p>Perhaps a better way to explain the searchbox functionality would be to compare it to the formula editor in Excel. I would like to be able to insert 'search formulas' and get the data results.</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>I am using Express for the project. </p>
  
  <p>Searchbox value that should work:</p>
  
  <blockquote>
    <p>{"pocet_nabidek":2}</p>
  </blockquote>
  
  <p>This is the approach I took, based on @x_maras suggestions:</p>
  
  <p><strong>Client side</strong></p>
  
  <pre><code>// send AJAX request when the search field changes
  $('#searchField').keyup(function() {
      clearTimeout(timer);
      var timer = setTimeout(function() {
  
              //call your function here
              q = $('#searchField').val();
              if (q.length != 0 &amp;&amp; q != undefined) {
  
                  var payload = "/api/zakazka?q="+replaceURLParam(q);
                  $.getJSON(payload, function(data){
  
                      console.log(data);
  
                  });
  
              }
  
          }, 500) // delay
  });
  </code></pre>
  
  <p><strong>Server side</strong> </p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  // ... more code ...
  
  router.get('/zakazka', function(req, res) {
  
      var pagesize = req.query["pagesize"];
      var offset = req.query["offset"];
      var q = req.query["q"];
  
      if (q != undefined || q != null) {
  
          console.log("got a query passed on!");
          q = decodeURI(q);
          q = JSON.parse(q);
          return
      } 
  
      var collection = req.db.get('zakazky');
  
      collection.find(q, {
          limit: pagesize,
          skip: offset
      }, function(e, docs) {
          if (e) {
              console.log(`Error: X doesn't seem to exist`);
          }
          if (docs != null &amp;&amp; docs.length != 0) {
              res.json(docs);
          } else {
              res.writeHead(404, {
                  "Content-type": "text/plain"
              });
              res.end(`Error: X doesn't seem to exist`);
          }
      });
  
  });
  </code></pre>
  
  <p><strong>If I modify the code as per below, the query works</strong></p>
  
  <pre><code>// This actually works: 
  // var q = {};
  // var selector = "pocet_nabidek";
  // q[selector] = Number(2);
  </code></pre>
  
  <p><strong>This is a sample of a document we're querying</strong></p>
  
  <pre><code>{
      "_id": ObjectId("568d91396912101c1007ab4e"),
      "cena": 1636363,
      "cena_celkem": 1500000,
      "cena_dopocitano": false,
      "created": "2015-04-07T13:45:10.420739",
      "datum_zadani": "2015-02-16",
      "dodavatel": "/api/v1/dodavatel/381836/",
      "druh_rizeni": "/api/v1/druh_rizeni/1116/",
      "id": 1312587,
      "modified": "2015-04-18T14:22:10.765733",
      "nazev": "Pohostinství",
      "pocet_nabidek": 2,
      "podporeno_eu": true,
      "popis": "Kurzy v oblasti pohostinství (formou profesní kvalifikace)",
      "ramcova_smlouva": true,
      "resource_uri": "/api/v1/zakazka/1312587/",
      "skupina": "490648-ISVZUS_2011",
      "typ_zakazky": "/api/v1/typ_zakazky/193/",
      "zadavatel": "/api/v1/zadavatel/131528/",
      "zdroj": "http://www.vestnikverejnychzakazek.cz/en/Form/Display/568547",
      "zdroj_nazev": "isvzus.cz",
      "cpv": ["80000000-4", "80400000-8", "", "", ""],
      "predpokladana_hodnota": "1 500 000,00"
  }
  </code></pre>