为了账号安全,请及时绑定邮箱和手机立即绑定

node +mongodb建站问题 Movie.fetch is not a function

node +mongodb建站问题 Movie.fetch is not a function

Aditya 2016-12-01 13:38:14
//app.js var express = require('express') var path = require('path') var mongoose = require('mongoose') var _ = require('underscore') var bodyParser  = require('body-parser'); var Movie = require('./models/movie') var port = process.env.PORT || 3000 var app = express(); mongoose.connect('mongodb://localhost/imooc') app.set('views',__dirname+'/views/pages')    app.set('view engine','jade')                app.use(bodyParser.urlencoded({ extended: false })) app.use(express.static(path.join(__dirname, 'res'))); app.listen(port) console.log('imooc started on port '+ port) //index page app.get('/',(req,res)=>{     Movie.fetch(function(err,movies){         if(err){             console.log(err)         }         res.render('index',{             title:'imooc 首页',             movies:movies         })     }) }) // schemas\movie.js var mongoose = require('mongoose') var MovieSchema = require('../schemas/movie') var Movie = mongoose.model('Movie',MovieSchema) module.exports = Movie //models\movies.js var mongoose = require('mongoose') var MovieSchema = new mongoose.Schema({     doctor: String,     title: String,     language: String,     country: String,     summary: String,     flash: String,     poster: String,     year: Number,     meta:{         createAt:{             type:Date,             default:Date.now()         },         updataAt:{             type:Date,             default:Date.now()         }     } }) MovieSchema.pre('save',function(next){       if(this.isNew) {                 this.meta.createAt = this.meta.updateAt = Date.now()     }     else{         this.meta.updateAt = Date.now()     }          next() }) MovieSchema.static = {     fetch: function (cb) {          return this             .find({})             .sort('meta.updateAt')             .exec(cb)     },     findById: function (id,cb) {             return this             .findOne({_id: id})             .exec(cb)     } } module.exports = MovieSchemaTypeError: Movie.fetch is not a function
查看完整描述

1 回答

已采纳
?
蜂之谷

TA贡献564条经验 获得超863个赞

MovieSchema.statics   

查看完整回答
2 反对 回复 2016-12-01
  • Aditya
    Aditya
    多谢大哥!但跑一边之后又是提示这个啊 (node:11888) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
  • Aditya
    Aditya
    多谢大哥!又遇到问题了,input(type="hidden",name="movie[id]",value="#{movie._id}")这个id是什么啊?
  • 蜂之谷
    蜂之谷
    你写错了吧 是 _id
点击展开后面1
  • 1 回答
  • 0 关注
  • 2389 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信