Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get node's id with cypher request?

Tags:

neo4j

cypher

I'm using neo4j and making executing this query:

MATCH (n:Person) RETURN n.name LIMIT 5

I'm getting the names but i need the ids too. Please help!

like image 559
Aleksandrenko Avatar asked Oct 05 '14 14:10

Aleksandrenko


People also ask

What is ID in Neo4j?

In Neo4j, "Id" is a default internal property for both Nodes and Relationships. That means, when we create a new Node or Relationship, Neo4j Database Server will assign a number for internal usage. It is incremented automatically.

When you create a relationship in Cypher You must specify a direction True or false?

Syntax: Creating relationships The connections capture the semantic relationships and context of the nodes in the graph. When you create the relationship, it must have direction. You can query nodes for a relationship in either direction, but you must create the relationship with a direction.

How do I return all nodes and relationships in Neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

What Cypher clauses can you use to create a node?

Contents. The CREATE clause is used to create nodes and relationships.


2 Answers

Since ID isn't a property, it's returned using the ID function.

MATCH (n:Person) RETURN ID(n) LIMIT 5
like image 161
subvertallchris Avatar answered Oct 05 '22 17:10

subvertallchris


Not sure how helpful or relevant this is, but when I'm using the NodeJS API the record objects returned from Cypher queries have an identity field on the same level as the properties object (e.g record.get(0).properties, record.get(0).identity). I'm assuming you aren't just doing plain Cypher queries and actually using a driver to send the queries - so you might not have to run another MATCH statement.

I'm aware that the OP is asking about Cypher specifically - but it might be helpful to other users that stumble upon this question.

like image 30
e.upton Avatar answered Oct 05 '22 19:10

e.upton