title: How to get data from mongodb to put in an option?
body: <p>I am creating a dashboard table for displaying the saved data in mongoDB. I already have a table and display all the data in the table, now what I want to achieve is to create a <code>select</code> element above the database table the <code>select</code> element should contains all the available dates from mongodb. For example I have 20 same dates of <code>05/25/2019</code> and 10 same dates of <code>05/26/2019</code> and 30 same dates of <code>05/29/2019</code> I want to display only three options which the dates said above in the <code>select</code> element. and if another dates is added in the database that should also be displayed on the <code>option</code> too.</p>
  
  <p>I tried doing on the same thing that I did on the table to my select options but of course like the data in the table it display all the same date so I had like 60 options where <code>30</code> were same dates of  <code>05/29/2019</code> and <code>10</code> were same dates of <code>05/26/2019</code> and <code>20</code> were the same dates of <code>05/25/2019</code> </p>
  
  <p>this is my <code>index.js</code></p>
  
  <pre><code>var express = require("express"),
  app = express(),
  bodyparser = require("body-parser"),
  mongoose = require("mongoose");
  mongoose.connect("mongodb://localhost:27017/sample", {useNewUrlParser: true});
  app.use(bodyparser.urlencoded({ extended: true }));
  app.set("view engine", "ejs");
  app.use('/views', express.static('views'));
  
  var nameSchema = new mongoose.Schema({
    route : String,
    origin : String,
    destination : String,
    estimatedTimeOfArrival : String,
    date : String,
    time : String
  },{
      collection : 'log'
  }) 
  
    var User = mongoose.model("User", nameSchema);
  
  app.get("/", function (req, res) {
  res.render("index",{ details: null })
  })
  
  
  app.get("/getdetails", function (req, res) {   
      User.find({}, function (err, allDetails) {
      if (err) {
          console.log(err);
      } else {
          res.render("index", { details: allDetails })
      }
  });
  });
  
  app.listen(1412, "localhost", function () {
  console.log("server has started at " + 1412);
  })
  </code></pre>
  
  <p>this is my <code>index.ejs</code></p>
  
  <pre><code>&lt;div  class="tableFixHead"&gt;
                              &lt;% if(details!=null) { %&gt;
                          &lt;table  id="myTable" &gt;
                              &lt;thead&gt;
                                  &lt;tr class="header" style=" color: white !important;font-weight:bold;"&gt;
                                      &lt;th scope="col"&gt;Route&lt;/th&gt;
                                      &lt;th scope="col"&gt;Origin &lt;/th&gt;
                                      &lt;th scope="col"&gt;Destination&lt;/th&gt;
                                      &lt;th scope="col"&gt;Estimated Time of Arrival &lt;/th&gt;
                                      &lt;th scope="col"&gt;Date &lt;/th&gt;
                                      &lt;th scope="col"&gt;Time&lt;/th&gt;
                                  &lt;/tr&gt;
                              &lt;/thead&gt;
                              &lt;% details.forEach(function(item){ %&gt;
                              &lt;tbody id="myTable" style="color:black;"&gt;     
                                  &lt;tr&gt;
                                      &lt;td&gt;&lt;%= item.route%&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;%= item.origin %&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;%= item.destination%&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;%= item.estimatedTimeOfArrival %&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;%= item.date%&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;%= item.time%&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/tbody&gt;
                              &lt;% }) %&gt;
                          &lt;/table&gt;
                          &lt;% } %&gt;
                      &lt;/div&gt;
  </code></pre>
  
  <p>and a sample html data <a href="https://jsfiddle.net/indefinite/3yzvemcg/2/" rel="nofollow noreferrer">https://jsfiddle.net/indefinite/3yzvemcg/2/</a></p>
  
  <p>The <code>dates</code> are coming from a web app. so after the user submit the form from the app it will saved in my mongoDB and right now I have many data in database and many are sent on the same dates and what I want to achieve is to get the all the dates saved in the database and if the some dates are the same it will only display as one and  <code>option</code> will be added if the dates were added too in the database. I'm really new at this so thank you in advanced.</p>