1

やあみんな、私はマングースとノードで遊んでみましたが、最も単純な実行でさえ問題があります...私はこのコードを持っています:

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)

これの何が悪いのか誰か知っていますか?ありがとう。

4

1 に答える 1

1

どのバージョンのマングースを使用していますか?

I ran into similar problems with mongoose < 1.1.0 which updating cured.

于 2011-05-10T19:17:13.927 に答える