TypeError:Object#<object>没有方法&#39; Schema&#39; </object>

时间:2014-08-27 09:20:24

标签: javascript node.js neo4j

这是我们用户模型的架构。但是当我在localhost中运行时,我收到一个错误:
TypeError:Object#没有方法'Schema'

// app/models/user.js
// load the things we need
var neo4j = require('neo4j');
var bcrypt   = require('bcrypt-nodejs');

// define the schema for our user model
var userSchema = neo4j.Schema({


    facebook        : {
        id          : String,
        token       : String,
        email       : String,
        firstName   : String,
        lastName    : String
    }

});

// checking if password is valid using bcrypt
userSchema.methods.validPassword = function(password) {
    return bcrypt.compareSync(password, this.local.password);
};


// this method hashes the password and sets the users password
userSchema.methods.hashPassword = function(password) {
    var user = this;

    // hash the password
    bcrypt.hash(password, null, null, function(err, hash) {
        if (err)
            return next(err);

        user.local.password = hash;
    });

};

// create the model for users and expose it to our app
module.exports = neo4j.model('User', userSchema);

这是我从控制台得到的错误:

C:\Users\kiit\WORKSPACE\People Discover App\app\model\user.js:7
var userSchema = neo4j.Schema({
                       ^
TypeError: Object #<Object> has no method 'Schema'
at Object.<anonymous> (C:\Users\kiit\WORKSPACE\People Discover App\app\model\user.js:7:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\kiit\WORKSPACE\People Discover App\config\passport.js:8:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)

1 个答案:

答案 0 :(得分:1)

我不确定您使用的是哪个库,但您的代码中有关于问题的线索,即:

&#34; neo4j.Schema&#34;

Schema中的大写字母S,如果它存在于api中,则意味着你需要使用关键字new(userSchema = new neo4j.Schema({...),除非api打破了一个基本的命名javascript中的规则。模式可能存在,如果存在,则需要将大写S更改为小写s。如果这两个选项都不起作用,则api可能不包含模式方法或模式构造。