-1

I am trying to create a simple server application in Node.js using the waterline-orientdb package where there are several users who can invoke several methods. Before a user can do anything, the user needs to authenticate with his username and password. Within this authentication the user object is given a token that will be piggybacked with the future requests. When a user is given a token, an update query is invoked. When invoking the update request I get the following error:

    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 }

The strange thing is that the update is executed, so this error doesn't have influence on the update request. But because I want to catch all errors, I can't just ignore this.

My model looks like this:

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'
        }
};

As you can see, I'm associating two users with eachother so that one user can follow the activities of the other user. When I delete the association (so follows and followed) the error also dissapears.

The piece of code where the updates happens looks like this:

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);
});

Does anyone has an idea on how to avoid this behavior or what the error even means?

Cerebres
  • 343
  • 3
  • 16
  • Where do you get the error? In orientdb or in the variable error in res.json? The last piece of code says nothing about what data exists in user[0] or the db, and what relations already exist. Perhaps log user[0] and see what it is you are trying to save. The code is hard to read as well. Nobody will even try to read it, format it. You lack ';' in quite a few lines, if you run your code through jslint you will get some nice tips. Did you ever find the solution? – oldwizard Feb 02 '15 at 09:40

1 Answers1

1

It seems to be a bug in the adapter.

You could try using:

npm install appscot/waterline-orientdb#refactor_collection

Apparently will be resolved in v.0.10.40

More info about it: https://github.com/appscot/waterline-orientdb/issues/43#issuecomment-75890992

ajkaanbal
  • 87
  • 1
  • 3