neo4jcyphergraphaware

Neo4j merge's not saving data


I have the following code using PHP & GraphAware:

$stack = $client->stack();
$stack->push('  MATCH (student:Student{id:123})
        MATCH (spring:Term{name:"Spring2017"})
        MATCH (class:Class{name:"Cypher101"})
        MERGE (student)-[:ENROLLED_IN]->(class)-[:FOR_TERM]->(spring)');
$results = $client->runStack($stack);

$res = $client->run('MATCH (n) RETURN count(n)');
print_r($res->records());

I have copied the example code found here: https://neo4j.com/developer/kb/understanding-how-merge-works/ and for some reason the print_r() returns the following:

Array
(
    [0] => GraphAware\Bolt\Record\RecordView Object
        (
            [keys:protected] => Array
                (
                    [0] => count(n)
                )

            [values:protected] => Array
                (
                    [0] => 0
                )

            [keyToIndexMap:GraphAware\Bolt\Record\RecordView:private] => Array
                (
                    [count(n)] => 0
                )

        )

)

If I run a CREATE command the query works fine but for some reason the code above won't. Can someone advise me what I'm doing wrong?


Solution

  • Your query seems correct.

    Check if these nodes exist in the Neo4j Database.

    NOTE: Multiple MERGE in a single query is not recommended, so try to use the first solution (creating the nodes separately).