1
所以。我試圖使用mongoose與expressjs項目一起使用mongoDB,並且出現此錯誤。expressjs,貓鼬,模式錯誤
throw new mongoose.Error.MissingSchemaError(name);
^
MissingSchemaError: Schema hasn't been registered for model "device".
我也是新來的,但這裏是我在哪裏得到的錯誤的VAR設備
var mongoose = require('mongoose');
var device = mongoose.model('device', device);
/* GET */
router.get('/', function(req, res) {
new device({
device_id : "Something happened"
}).save(function(err, device, count){
res.redirect('/');
});
});
這裏index.js我的源代碼是我在app.js代碼:
//mongo start
var mongo = require('mongodb');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var device = new Schema({
device_id : String
});
var device = mongoose.model('device', device);
var db = mongoose.connect('mongodb://127.0.0.1:27017/database');
mongoose.connection.once('connected', function() {
console.log("Connected to database")
});
//mongo end