【问题标题】:Node.js waterline-orientdb update failNode.js waterline-orientdb 更新失败
【发布时间】:2014-12-19 10:55:16
【问题描述】:

我正在尝试使用 waterline-orientdb 包在 Node.js 中创建一个简单的服务器应用程序,其中有多个用户可以调用多种方法。在用户可以做任何事情之前,用户需要使用他的用户名和密码进行身份验证。在此身份验证中,用户对象将获得一个令牌,该令牌将与未来的请求一起携带。 当用户获得令牌时,将调用更新查询。调用更新请求时出现以下错误:

    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] 或数据库中存在哪些数据,以及已经存在哪些关系。也许登录 user[0] 并查看您要保存的内容。代码也很难阅读。甚至没有人会尝试阅读它,格式化它。你缺少';'在相当多的行中,如果您通过 jslint 运行代码,您将获得一些不错的提示。你找到解决方案了吗?

标签: node.js sails.js orientdb waterline


【解决方案1】:

这似乎是适配器中的错误。

您可以尝试使用:

npm install appscot/waterline-orientdb#refactor_collection

显然会在 v.0.10.40 中解决

更多信息:https://github.com/appscot/waterline-orientdb/issues/43#issuecomment-75890992

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多