LearnerFreak
LearnerFreak

Reputation: 69

Neo4j :Using cypher query to retrieve auto generated id of the node

I am new to neo4j.

I want to retrieve the auto generated id of the node using a cypher query.

I am using php.

How is it possible? Also,how do I get just the id of the node in a php variable?

Upvotes: 1

Views: 950

Answers (1)

jjaderberg
jjaderberg

Reputation: 9952

MATCH (n)
RETURN ID(n) as nodeId

See docs: http://docs.neo4j.org/chunked/milestone/query-functions-scalar.html#functions-id

EDIT:

I don't know PHP well but assuming you're using neo4jphp I guess the general idea would be something like

$client = new Everyman\Neo4j\Client();
$queryString = "MATCH (n) RETURN ID(n) as nodeId";
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
$result = $query->getResultSet();
echo $result[0]['nodeId']

You will want to read up on neo4jphp here, particularly how to use cypher. Or you can use php cURL with Neo4j REST API.

Upvotes: 2

Related Questions