1

I have am having trouble parsing data from a mongodb through a route. I'd like to return the title fields for each object.

I have the following schema:

var mongoose  = require('mongoose');
var Schema    = mongoose.Schema;

var GiveSchema   = new Schema({
        title: String,
        shortname: String,
        contents: String,
        image: String,
        category: String
    });

module.exports = mongoose.model('GiveData',  GiveSchema);

I'm storing the schema in this variable:

var Givedata = mongoose.model( 'GiveData' );

Here is my route:

app.get('/', function(req, res) {
    res.render('index.ejs',{
      list: Givedata.title,
      bootstrappedUser: req.user,
      something: req.body,
      page: 'home'
    });
});

I'm using this logic in my template, but coming up with 'undefined'

<% for(var i=0; i< list.length; i++) { %>
    <a href="/"><li><%= list[i] %></li></a>
    <% } %> 
Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
byrdr
  • 5,197
  • 12
  • 48
  • 78

1 Answers1

0

In order for EJS to work you'll have to set ejs as your view engine:

app.set('view engine', 'ejs');
yotamsha
  • 384
  • 1
  • 7