I am new to the MEAN stack. Could someone please help me understand this:
I create a new task and save it, but in the index page I can only see.
_id: 5834ba711401ea28643cdfb8, __v: 0
No other attributes. However
docs.length
in tasks/index.jade grows with every added task.
What am I doing wrong?
Thank you very much!
tasks.js
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/todo_development');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var Task = new Schema({
task: String
});
var Task = mongoose.model('Task', Task);
router.get('/', function(req, res) {
Task.find({}, function (err, docs){
res.render('tasks/index', {
title: ' Ornbo | Todos index view' ,
docs: docs
});
});
});
router.get('/new', function(req,res){
res.render('tasks/new.jade', {
title: 'New Task'
});
});
router.post('/', function(req, res){
var task = new Task(req.body.item);
task.save(function(err){
if(!err){
res.redirect('/tasks');
} else {
res.redirect('/tasks/new');
}
});
});
module.exports = router;
tasks/index.jade
- if(docs.length)
span number of records: #{docs.length}
table
tr
th Task
each task in docs
tr
td Do: [#{task}]
What I have tried:
I have tried renaming the attribute and looking at the DB in MongoVUE.