Frage

I am using OrientDB server side Javascript functions to define business logic. My query is how add, delete and check for existence with LINKSET in Javascript functions of OrientDB ?

Just for example, if my company.employees = [#4:1, #4:5, #4:3]

  1. How can I add #4:6 to linkset ? After addition it should be [#4:1, #4:5, #4:3, #4:6]

  2. How can I delete #4:5 from linkset ? After deletion it should be [#4:1, #4:3, #4:6]

  3. If I add #4:1 again to linkset, will it check for duplicate and return error or do I need to check problematically before adding to linset ? If I need to do it, how to do it ?

I am sure there must be some methods to add, delete and check existence on linkset & linkmap, I am not just aware of those.

Any pointers will be helpful.

War es hilfreich?

Lösung

Look at the official documentation: https://github.com/orientechnologies/orientdb/wiki/SQL-Update#example-3-add-a-value-into-a-collection. So:

1) If your record has RID #13:33:

update #13:33 add company.employees = #4:6

2) The same (https://github.com/orientechnologies/orientdb/wiki/SQL-Update#example-4-remove-a-value-from-a-collection):

update #13:33 remove company.employees = #4:5

3) With set you cannot have duplicates, so if you add the same item multiple times, it's simply ignored with no errors.

Andere Tipps

The syntax has changed in OrientDB v3.0, according to this post:

Now, to add an element to the linkset you need to use the concatenation syntax which is here. http://orientdb.com/docs/3.0.x/sql/SQL-Syntax.html in Array concatenation

So your add example would be:

update #13:33 set company.employees= company.employees || #4:5

Remove has not changed so syntax is still:

update #13:33 remove company.employees = #4:5
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top