Mongoose中model.find()的查询结果报“Cannot read property 'userName' of undefined”

发布于 2014/07/24 21:02
阅读 1K+
收藏 0

代码如下:

//model/model.js
var mongoose = require('mongoose');

var userSchema = new mongoose.Schema({
  userName: String,
  email: String,
  phone: { type: Number, min: 11 }
});

mongoose.connect('mongodb://localhost/form');

module.exports = userSchema;

//router/list.js
var mongoose = require('mongoose');
var express = require('express');
var router = express.Router();
var userSchema = require('../model/model');
var userInfo = mongoose.model('userInfo', userSchema);

router.get('/list', function(req, res) {
  res.render('list', { title: 'Express', data: userInfo.find() });
});

module.exports = router;

//views/list.jade
extends layout

block content
  h1= title
  p Welcome to #{title}
  ul.list
    each val, index in data
      li
        strong= val.userName
          //span= val.email
          //strong= val.phone



最后浏览器中显示“Cannot read property 'userName' of undefined”
加载中
0
渊
已解决~
0
穿裤衩闯天下
穿裤衩闯天下
楼主分享下怎么解决的,也遇到这个问题了,google暂时 没解决
返回顶部
顶部