javascript - 类型错误 : Object #<Object> has no method 'Schema'

标签 javascript node.js neo4j

这是我们的用户模型的架构。但是当我在本地主机中运行时,我收到错误:
类型错误:对象#没有方法“架构”

// 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)

最佳答案

我不确定您正在使用哪个库,但您的代码中有一条线索可以说明问题所在,即:

“neo4j.Schema”

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

关于javascript - 类型错误 : Object #<Object> has no method 'Schema' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25523350/

相关文章:

javascript - 使用 jQuery 连接两个选择选项 val() 的问题

node.js - Gulp Stream 完成并带有 promise

javascript - 我正在将 ytdl-core 用于音乐机器人,它一直输出播放未定义

lucene - 在 Neo4j 上通过带有 html 标记的富文本进行全文搜索

docker - plesk 上 docker 中的 Neo4j(3.4.17、3.5.13、4.0.0)不使用/ssl 中提供的 SSL 证书,而是尝试删除它们并进行自己的自签名

javascript - 通过输入改变立方体旋转速度(threejs)

javascript - OnUnload 警报错误 "NS_ERROR_NOT_AVAILABLE"

node.js - 无法安装 npm 包 ||没有权限

macos - 启动 Neo4j 失败 : Address localhost:7474 is already in use, 无法在 Mac OSX 上绑定(bind)到它

javascript - 通过 service-worker 的请求完成了两次