Displaying all documents from mongo in a dropdown

Hello humans,
How would i get every document and display a certain value in a dropdown using mongoose and express?


Hi there @anon43649539
Once again ejs is the way to go with this. Basically you need to do Model.find, send that through to the ejs file and then use foreach to add each one to the html dropdown

Could I have a short code snippet for the mongoose and for each part

I’ll send in the morning (I’m in the UK). In the meantime I urge you to try and find it out yourself. The find function in Mongoose has many tutorials. It returns an array so you can do foreach on the array and get the different values in each object :slight_smile:


1 Like

ok but how do i then display it in a dropdown?

bump @EddiesTech

Can you share what have you have so far?

@anon43649539 This is the assuming you have performed a mongoose find and save the result as a variable called documents and then sent it through to the ejs file when rendering

<% documents.forEach(document =>{%>
<option value="<%=document.name%>"><%= document.name %></option>

thank you :slight_smile: