How to get data from mongodb to put in an option? How to get data from mongodb to put in an option? mongoose mongoose

How to get data from mongodb to put in an option?


If I understand well your problem, you want to find all distinct dates from your User model. Maybe your solution is the distinct mongoose option.
Try this in your index.js:

User.find().distinct('date', function(err, dates) {    // dates are an array of all distinct dates.    if (err) {        console.log(err);    } else {        res.render("index", { dates: dates })    }});

And in your ejs file add this.

// display select only when 'dates' array is defined.<% if (locals.dates) { %>     <select name="date" id="dates">    <% dates.forEach(function(date){ %>        <option><%= date %></option>    <% }) %>    </select><% } %>