Skip to content

REMOVE clause

Marijn van Wezel edited this page Dec 15, 2022 · 5 revisions

The REMOVE clause is used to remove properties from nodes and relationships, and to remove labels from nodes.

Query::remove(Label|Property|(Label|Property)[] $expressions): Query

Parameters

  • $expressions : A single property or label to remove, or a non-empty list of properties and labels to remove.

Relevant methods

  • addExpression(Label|Property ...$expressions): self : Add one or more labels and properties to remove.

Examples

Remove a property

$a = node()->withProperties(['name' => 'Andy']);
$query = query()
    ->match($a)
    ->remove($a->property('age'))
    ->returning([$a->property('name'), $a->property('age')])
    ->build();

$this->assertStringMatchesFormat("MATCH (%s {name: 'Andy'}) REMOVE %s.age RETURN %s.name, %s.age", $query);

Remove a label from a node

$n = node()->withProperties(['name' => 'Peter']);
$query = query()
    ->match($n)
    ->remove($n->labeled('German'))
    ->returning($n->property('name'))
    ->build();

$this->assertStringMatchesFormat("MATCH (%s {name: 'Peter'}) REMOVE %s:German RETURN %s.name", $query);

Remove multiple labels from a node

$n = node()->withProperties(['name' => 'Peter']);
$query = query()
    ->match($n)
    ->remove($n->labeled('German', 'Swedish'))
    ->returning($n->property('name'))
    ->build();

$this->assertStringMatchesFormat("MATCH (%s {name: 'Peter'}) REMOVE %s:German:Swedish RETURN %s.name", $query);

External links