我正在寻找我的问题,但即使不知道问题出在哪里。Nodejs,Mongoose和Jade没有从数据库中获得数据
我得到它在我的路线设置标题,但没有从数据库中的数据...
我的模型:
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
the只有一个我在页面显示是
Blog_
所以我做错了什么?
在错误的文件,只说:“不能读取属性‘标题’的未定义”
所以文章对象未设置......但是为什么呢?
非常感谢
编辑1:
变化article.title第不会改变任何东西在日志文件中
是
GET /blog/articles HTTP/1.1 304 - - 3 ms
编辑2 :
似乎节点犯规从数据库获取任何数据... 和是有一个TESTDATA集;)
的console.log() - >
错误:空
文档: []
的解决办法是张贴答案
模型部分,你可以改变'article.title'到'article'玉石用于测试目的?我怀疑'article'是未定义的,因此解释了你的错误信息。 – alandarev
尝试''console.log(docs)'在那里。我知道没有标准,但是你已经在我希望的地方发布了'.connect'。 –