开发者

Mongoose problem: schema not defined

开发者 https://www.devze.com 2023-03-04 23:53 出处:网络
Hey guys, I\'ve been trying to play with mongoose & node, but I have some problem regarding even the simplest run...

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:

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: S开发者_C百科tring,
  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消