Cannot overwrite search model once compiled
我使用以下代码使用Node.js和MongooseJS搜索MongoDB数据库。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | var express = require('express'); var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/searches'); var app = express(); app.set('view engine', 'ejs'); app.get('/', function(req, res){ res.render('index'); }); app.get('/search', function(req, res){ var keyword = req.query.q; var searchModel = mongoose.model('search', { title: String, keywords: String, desc: String, link: String }, 'search'); searchModel.find(function(err, doc){ if (err) throw err; res.send(doc); }); }); app.listen(9000, function(){ console.log('Server listening on http://localhost:9000'); }); |
当我第一次运行时,没有错误,并按原样返回所有记录。但是,当我刷新页面时,我收到一条错误消息:
Cannot overwrite
search model once compiled
这可能是什么原因?
不得在
在符合
第二次调用