[英]Mongoose problem: schema not defined
Hey guys, I've been trying to play with mongoose & node, but I have some problem regarding even the simplest run... I have this code: 大家好,我一直在尝试使用猫鼬和node,但是即使是最简单的运行,我也有一些问题...我有以下代码:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var db = mongoose.connect('mongodb://localhost/db');
var User = new Schema({
email: {
type: String,
index: { unique: true }
},
name: String,
lastseen: Date,
isonline: Boolean,
hashed_password: String,
salt: String
});
mongoose.model('User', User);
var User = db.model('User');
var u = new User();
u.name = 'Foo';
u.save(function() {
User.find().all(function(arr) {
console.log(arr);
console.log('length='+arr.length);
});
});
Which should run, since it's an example code... but I have this error: 应该运行,因为它是示例代码...但是我遇到了这个错误:
node.js:181
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: Schema is not defined
at Object.<anonymous> (myfile.js:12:1)
at Module._compile (module.js:420:26)
at Object..js (module.js:426:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)
at Array.<anonymous> (module.js:439:10)
at EventEmitter._tickCallback (node.js:173:26)
Does anyone of you know what's wrong with this? 你们当中有人知道这是怎么回事吗? Thanks. 谢谢。
Which version of mongoose are you using? 您正在使用哪个版本的猫鼬?
I ran into similar problems with mongoose < 1.1.0 which updating cured. 我遇到了猫鼬<1.1.0的类似问题,该问题已得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.