Cypher: Get info from deleted relationships

会有一股神秘感。 提交于 2019-12-10 10:44:28

问题


MATCH (n:Topic { mongoId: {_id} })-[r]-() DELETE n,r RETURN r;

That returns the error 'Error: Relationship 1509 has been deleted'.

However, I need r.mongoId to delete entries in another database.

How do I do this with Neo4j 2.2.3?

I'm doing this through the Seraph library. Is there a way to collect a property, delete the relationships, and return the collection?

I just need this data: MATCH (n:Topic { mongoId: _id })-[r]-() RETURN COLLECT(r.mongoId);

Thanks!


回答1:


You can use a WITH clause to alias the data you want to return before deleting the node and relationship. Something like this:

MATCH (n:Topic {mongoId: {_id} })-[r]-() 
WITH r.mongoId as docId, n,r 
DELETE n,r 
RETURN docId

Or you could break it up into two queries, one to retrieve the property you want, then the second to delete the relationship and node.

EDIT: you most likely want to specify a directed relationship to avoid duplicate docId properties returned:

MATCH (n:Topic {mongoId: {_id} })-[r]->()
...


来源:https://stackoverflow.com/questions/31124541/cypher-get-info-from-deleted-relationships

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!