Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-20-2021 02:16 PM
I need node id as property, how can I achieve?
RETURN { id(u): 23, value: 'value' } // ERROR
Result:
{
23: 23,
value: 'value'
}
04-20-2021 04:49 PM
This will give you the node id of the n node(s) and put them as property of the n nodes(s).
MATCH (n)
SET n.id = id(n)
04-21-2021 02:41 AM
That's not what I'm looking for. I wanted to return id as property not setting it.
04-21-2021 03:06 AM
Hello @ri8ika
You can get what you want with APOC plugin but you can only generate String key:
MATCH (n)
WHERE id(n) = 23
RETURN apoc.map.setKey({}, toString(id(n)), id(n))
OR
MATCH (n)
WHERE id(n) = 23
RETURN apoc.map.fromLists([toString(id(n)), "value"], [id(n), "value"])
Regards,
Cobra
04-22-2021 06:23 AM
Wow, it's cool. But I am not using apoc. Isn't there anyway to do it without apoc?
I tried:
RETURN {toString(id(n)): id(n)} // Error
04-22-2021 06:34 AM
I'm afraid that APOC is the only solution to do what you want.
04-24-2021 09:45 AM
Indeed if you are trying to do something like assigning a dynamic name to a property based on an id, Cypher is not build to do things like dynamic property name, it's meet to be used as a query language first.
APOC is really easy to install, the plugin table from Neo4j Desktop, and you have an almost but quite really complete documentation here.
All the sessions of the conference are now available online