嘿伙计们,我一直在尝试使用猫鼬和节点,但即使是最简单的运行我也遇到了一些问题......我有这个代码:
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);
});
});
哪个应该运行,因为它是一个示例代码......但我有这个错误:
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)
你们有谁知道这有什么问题吗?谢谢。