node.js - gremlin create edge while satisfying multiplicity constraint,if violated drop existing edge then create else just create it -
i struggling quite time solve problem like
i have graph in there defined multiplicity constraints . when new edge being created either new edge can created or can violate multiplicity constraint due data being changed.
now when data has changed need delete/drop existing edge , create new one. problem. not able drop , create edge in single go.
what have been trying sending query gremlin server via node-gremlin module of nodejs. relation trying create [merchant]-1--(sells)--*-> [product] . in given scenario 1 merchant can sell product . when other merchant starts selling product. need update reflect new relation between them. may case no 1 selling new edge has created. created edge returned.
29 jun 13:41:04 - [error: edge given label exists on in-vertex , label [sells] in-unique (error 597)] 29 jun 13:41:04 - { text: 'g.v().has(sidkey,sidval).ine(edgelabel).drop();graph.tx().commit();g.v().has(fidkey,fidval).oute(edgelabel).inv().has(sidkey,sidval).trynext().orelseget{g.v().has(fidkey,fidval).next().addedge(edgelabel,g.v().has(sidkey,sidval).next());};', params: { fidkey: 'merchant_id', fidval: 20230, sidkey: 'product_id', sidval: 184504, edgelabel: 'sells' } }
the flow ii trying achieve this
find if existing edge present -> delete existing edge -> commit delete edge command --> create new edge --> commit new edge.
in above query have not written commit statement add edge because committing add edges in bulk.
i not able figure out how proceed solve problem . great.
you need iterate()
on drop operation before committing transaction.
g.v().has(sidkey,sidval).ine(edgelabel).drop().iterate(); graph.tx().commit();
this common stumbling block , has been discussed previously: gremlin drop() isn't working via java api
Comments
Post a Comment