title: Query MongoDB with input form
body: <p>I have a MongoDB aggregate framework that uses a <code>startDate</code>, <code>endDate</code> and <code>intervalValue</code> to query my database. However these variables are hardcoded. I would like to use a datepicker to send <code>startDate</code>, <code>endDate</code> and <code>intervalValue</code>from a webpage. </p>
  
  <p>I initially thought I should split the JS file. One handling the request from the webpage and the other handling the <code>GET</code> function. Unfortunately I have reached a dead-end. I'm unable to use variables declared in <code>sandbox.js</code> in <code>test.js</code>.</p>
  
  <p>Also I'm a bit confuse on how to structure my JS files to input the date and display the output. </p>
  
  <p><strong>sandbox.js</strong></p>
  
  <pre><code>function myTime() {
  
  
      var startValue = document.getElementById("startTime").value;
      var endValue = document.getElementById("endTime").value;
      var intervalValue = document.getElementById("interval").value;
      var startDate = new Date("1/1/2015 " + startValue);
      var endDate = new Date("1/1/2015 " + endValue);
      var offset = intervalValue * 1000 * 60;
  }
  </code></pre>
  
  <p><strong>test.js</strong></p>
  
  <pre><code>{ $match : { datetime : { $gt : startDate, $lt : endDate } } },
    {
     $group: {
      _id:{
      "$add": [
       { "$subtract": [
       { "$subtract": [ "$datetime", new Date(0) ] },
       { "$mod": [
      { "$subtract": ["$datetime" , new Date(0) ] },
      offset]}] },
      new Date(0)
       ]},
              Humidity: {$avg: "$humidity"},
              Temperature: {$avg: "$temperature"}
  
              },
              },
  
        { $project : { _id : 1 , Humidity : 1, Temperature: 1 } },
         // { $limit : 10 },
         { $sort :  {"_id":1, "Humidity":1, "Temperature": 1}}
  </code></pre>
  
  <p>I will be glad if I can get some help. Thanks</p>