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