This is my first time writing an MVC application in Node / Express / Mongoose, so I can really take some help. My .find () command just doesn't find anything !: (
The structure is that I have a folder / application in the root. / app contains / models (circuits), / controllers and / views in it. And I have app.js outside at the root.
Somewhere in app.js:
// all necessary config/setup stuff.. var mongoose = require('mongoose'); mongoose.connect(config.db); var app = express(); require('./config/routes')(app)
In the routes.js file:
var skills = require('../app/controllers/skills'); app.get('/', skills.showall);
My skills.js controller contains:
var Skill = require('../models/skill'); exports.showall = function(req, res) { Skill.find({}, function(err, docs){ if (!err) { res.render('index', {title: 'Skilldom', skills: docs}); } else { throw err; } }); }
Finally, my skill.js model contains:
var mongoose = require('mongoose'); //Skill schema definition var skillSchema = new mongoose.Schema({ name: String, length: String, }); var Skill = mongoose.model('Skill', skillSchema); module.exports = Skill;
My index view displays, so I see the contents from my index.jade template, but for some reason the find command in the model does not get anything. I can confirm that my database (in MongoHQ) has real data.
Any thoughts?