Javascript 类型错误:对象#<;对象>;没有方法';模式';
这是我们的用户模型的模式。但是当我在localhost中运行时,我得到一个错误:Javascript 类型错误:对象#<;对象>;没有方法';模式';,javascript,node.js,neo4j,Javascript,Node.js,Neo4j,这是我们的用户模型的模式。但是当我在localhost中运行时,我得到一个错误: TypeError:对象#没有方法“Schema” 这是我从控制台得到的错误: C:\Users\kiit\WORKSPACE\People Discover App\App\model\user.js:7 var userSchema=neo4j.Schema({ ^ TypeError:对象#没有方法“Schema” 在对象上。(C:\Users\kiit\WORKSPACE\People Discover A
TypeError:对象#没有方法“Schema” 这是我从控制台得到的错误:
C:\Users\kiit\WORKSPACE\People Discover App\App\model\user.js:7
var userSchema=neo4j.Schema({
^
TypeError:对象#没有方法“Schema”
在对象上。(C:\Users\kiit\WORKSPACE\People Discover App\App\model\user.js:7:24)
在模块处编译(Module.js:456:26)
在Object.Module.\u extensions..js(Module.js:474:10)
在Module.load(Module.js:356:32)
在Function.Module.\u加载(Module.js:312:12)
at Module.require(Module.js:364:17)
根据需要(模块js:380:17)
在对象上。(C:\Users\kiit\WORKSPACE\People Discover App\config\passport.js:8:11)
在模块处编译(Module.js:456:26)
在Object.Module.\u extensions..js(Module.js:474:10)
我不确定您使用的是哪一个库,但您的代码中有一条线索可以说明问题所在,即:
“neo4j.Schema”
如果api中存在大写字母S,则表示需要使用关键字new(userSchema=new neo4j.Schema({…),当然,除非api打破了javascript中的基本命名规则。模式可能存在,如果存在,则需要将大写字母S更改为小写字母S。如果这两个选项都不起作用,则您的api可能不包含模式方法或模式构造。显然,
r出现了问题equire('neo4j');
…那么,您使用的是哪一个Node.js库?这一个?您阅读了该库的文档了吗?没有模式方法。看起来您试图使用neo4j来代替Mongoose,这是行不通的。@Ben Fortune:谢谢
// 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);