0

I need to update a specific record in my User class. I don't have any field with a unique index so I need to use the @rid field.

How can I use orientjs to update a specific record with dynamic properties ?

I would like to use the query builder if possible because my updated record is in the request body.

Here is what I've tried :

var id = '#' + req.param('id');

db.update('User').set(req.body).where({@rid: id}).scalar()
.then(function (total) {
console.log('updated', total, 'users');
});

It gives me a syntax error because I cannot use the @rid in the where clause :

db.update('User').set(req.body).where({@rid: id}).scalar()
                                           ^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/alexandre/Documents/bitbucket/rest-api/server/routes/index.js:4:12)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/alexandre/Documents/bitbucket/rest-api/server/server.js:25:14)
at Module._compile (module.js:460:26)
AlexB
  • 3,518
  • 4
  • 29
  • 46

1 Answers1

2

try

db.update(id).set(req.body).scalar()

where id is the @rid of the record you want to update

wolf4ood
  • 1,939
  • 10
  • 8
  • It works but what if I need to make sure it is a certain class ex: User that I am updating ? – AlexB Jul 07 '15 at 16:54
  • you can see here the docs http://orientdb.com/docs/last/Tutorial-Classes.html basically if you have a rid it is a unique id among classes so you will not have duplicates as the rid is composed by cluster id and cluster position – wolf4ood Jul 07 '15 at 18:55