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)
你们中有谁知道这有什么问题吗? 感谢。
答案 0 :(得分:1)
您使用的是哪种版本的猫鼬?
我遇到了与mongoose相似的问题&lt; 1.1.0更新已治愈。