swelet
swelet

Reputation: 8732

Neo4j/cypher: Return id as property

I've got this super simple cypher query for my juicy graph database of two nodes:

MATCH (n) RETURN n

And it's returning the two nodes as such:

{
"results": [
    {
        "columns": [
            "n"
        ],
        "data": [
            {
                "row": [
                    {
                        "name": "node 1",
                        "description": "This is my first node."
                    }
                ]
            },
            {
                "row": [
                    {
                        "name": "node 2",
                        "description": "This is my second node."
                    }
                ]
            }
        ]
    }
],
"errors": []
}

I was kind of expecting to get the id out as a property with "name" and "description". How can i get it in there? I know I can go something like:

MATCH (n) RETURN n, id(n)

But that would put the id outside the object and I don't want that.

Upvotes: 1

Views: 2178

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41706

You can use map {foobar:42}and collection structures in Cypher [1,2,3]

so you can return:

RETURN {id:id(n), labels: labels(n), data: n}

or you can use

{"statement":"match (n) return n","resultDataContents":["graph"]}

as additional parameter to your POST request.

Upvotes: 2

Related Questions