我想在Node.js中使用waterline-orientdb包创建一个简单的服务器应用程序,其中有几个用户可以调用多个方法。在用户可以做任何事情之前,用户需要使用他的用户名和密码进行身份验证。在这个身份验证中,用户对象被赋予一个将被未来请求捎带的令牌。 向用户授予令牌时,会调用更新查询。当调用更新请求我收到以下错误:Node.js waterline-orientdb更新失败
ERROR err: { [OrientDB.RequestError: expression item ']' cannot be resolved because current record is NULL]
name: 'OrientDB.RequestError',
message: 'expression item \']\' cannot be resolved because current record is NULL',
data: {},
previous: [],
id: 1,
type: 'com.orientechnologies.orient.core.exception.OCommandExecutionException',hasMore: 0 }
奇怪的是,该更新被执行,那么这个错误不会对更新请求的影响。但是因为我想抓住所有的错误,所以我不能忽视这一点。
我的模型看起来是这样的:
module.exports = {
tableName: 'User',
identity: 'dbuser',
schema: true,
attributes: {
id: {
type: 'string',
primaryKey: true,
columnName: '@rid'
},
username: {
type: 'string',
required: true,
unique: true
},
password: {
type: 'string',
required: false
},
token: {
type: 'string'
},
follows: {
collection: 'dbuser',
via: 'followed',
dominant: true
},
followed: {
collection : 'dbuser',
via: 'follows'
}
};
正如你所看到的,我的两个用户海誓山盟关联,这样一个用户可以跟随其他用户的活动。当我删除关联(如下和之后)时,错误也消失。
的一段代码,其中更新偏偏喜欢这个样子:
user[0].token = generateToken(user[0])
dbuser.update({
id: user[0].id
}, user[0]).exec(function (error, data) {
if (error) res.json(401, {
code: 401,
error: "Token could not be updated"
})
res.json(user);
});
有没有人有关于如何避免此行为或错误甚至什么手段的想法?
你从哪里得到这个错误吗?在orientdb或res.json中的变量错误?最后一段代码没有说明用户[0]或数据库中存在什么数据,以及已经存在的关系。也许登录用户[0],看看你想要保存的是什么。代码很难阅读。没有人会尝试阅读,格式化它。你缺少';'在相当多的几行中,如果你通过jslint运行你的代码,你会得到一些很好的提示。你有没有找到解决方案? – oldwizard 2015-02-02 09:40:49