Search code examples
orientdb

How to add, delete and check existence with LINKSET in OrientDB?


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.


Solution

  • 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.