第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

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?首頁(yè)', ????????????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貢獻(xiàn)564條經(jīng)驗(yàn) 獲得超863個(gè)贊

MovieSchema.statics ??

查看完整回答
2 反對(duì) 回復(fù) 2016-12-01
  • Aditya
    Aditya
    多謝大哥!但跑一邊之后又是提示這個(gè)啊 (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}")這個(gè)id是什么?。?/div>
  • 蜂之谷
    蜂之谷
    你寫錯(cuò)了吧 是 _id
點(diǎn)擊展開后面1
  • 1 回答
  • 0 關(guān)注
  • 2428 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)