Quantcast
Channel: Mongoose model is not returning data - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Mongoose model is not returning data

$
0
0

I'm trying to setup a model but there is no data rendering on the page (using a handlebars view engine).

I have the following in an app.js file:

// Mongoose setupvar mongoose = require('mongoose');mongoose.connect('mongodb://localhost/nickinumbers');

And then this is the model I setup for the data I need returned this is ina nickinumbers.js file:

 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var NickiNumberSchema = new Schema({   number: {type: 'String', required: true},   firstName: {type: 'String'} }); var NickiNumber = mongoose.model('Nickinumber', NickiNumberSchema); module.exports = NickiNumber;

Finally, my index.js router file contains:

var express = require('express');var router = express.Router();var NickiNumber = require('../models/nickinumbers');    router.get('/', function(req, res) {        NickiNumber.find(function(err, nums) {            if (err) return console.error(err);            res.render('index', {title: 'Users', nums: nums});    }); });module.exports = router;

I'm not seeing any errors on the server or in the console and I can't figure out why this isn't working. Any help is appreciated!


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>