【发布时间】:2014-08-12 00:02:03
【问题描述】:
我正在寻找我的问题,但我什至不知道问题出在哪里。
我得到了在我的路线中设置的标题,但没有来自数据库的数据...
我的模特:
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.Types.ObjectId;
var blogSchema = new Schema({
title: { type: String, required: true },
author: { type: String, required: true },
body: { type: String, required: true },
date: { type: String, required: true },
hidden: Boolean
});
module.exports = mongoose.model('Blog', blogSchema);
我的路由器:
var express = require('express'),
Blog = require('../models/blog'),
moment = require('moment');
moment.lang('de');
var router = express.Router();
router.get('/articles', function(req, res) {
Blog.find(function(err, docs){
return res.render('blog/articles', {
title: 'Blog_',
articles: docs
});
});
});
app.use('/blog', router);
我的玉
extends ../layouts/default
include ../elements/form-elements
block content
h1= title
each article in articles
.col-md-12
div.title= article.title
我在页面上显示的唯一一个是
Blog_
那我做错了什么?
在错误文件中它只说:“无法读取未定义的属性'title'”
所以文章对象没有设置...但是为什么呢?
非常感谢
编辑 1:
将 article.title 更改为文章不会改变任何内容
在日志文件中是
GET /blog/articles HTTP/1.1 304 - - 3 ms
编辑 2:
似乎节点没有从数据库中获取任何数据... 是的,有一个测试数据集;)
console.log() ->
错误:空
文档:[]
解决方案发布为答案
【问题讨论】:
-
你能把jade中的
article.title改成article进行测试吗?我怀疑article未定义,因此解释了您的错误消息。 -
也试试
console.log( docs )。我知道没有标准,但您在我希望的某个地方发布了.connect。
标签: node.js mongodb express mongoose pug