-
Notifications
You must be signed in to change notification settings - Fork 274
Neo4j::Cypher With
The ability to chain queries together allows for powerful constructs. In Cypher, the WITH clause is used to pipe the result from one query to the next.
with is also used to separate reading from updating of the graph. Every sub-query of a query must be either read-only or write-only.
There are two different ways of using with method: on paths or on the global context
Example of using with on a path
node(1) <=> node(:other_person).ret.with(count) { |_, foaf| foaf > 1 }) >> nodeNotice that the first argument in the with block is the node(:other_person) (the object on which the with method operates on). Since the first argument is not used (in the example) in the block we avoid declaring a variable using _ as argument name. The foaf argument corresponds to the count argument - the first argument on the with method.
Same as
START v2=node(1) MATCH (v2)--(other_person)-->(v3) WITH other_person,count(*) as v1 WHERE v1 > 1 RETURN other_person
The example above can also be written using the with method on the global context:
(node(1) <=> node(:other_person)) >> node
with(node(:other_person), count) {|_, foaf| foaf > 1}
ret :other_personGenerates: START v2=node(1) MATCH (v2)--(other_person)-->(v3) WITH other_person,count(*) as v1 WHERE v1 > 1 RETURN other_person
Example:
node.new(:name => 'Andreas', :age => 42)Same as CREATE (v1 {name : 'Andreas', age : 42}) RETURN v1
Delete a node:
node(4).delSTART v1=node(4) DELETE v1
Delete a relationship
node(3) > rel('r').del > node.delSame as START v1=node(3) MATCH (v1)-[r]->(v2) DELETE r,v2
Example:
node(1).create_path { |n| n > rel(:friends) > node(2) }Same as START v1=node(1),v2=node(2) WITH v1 CREATE (v1)-[:friends]->(v2)
See the RSpecs for more examples see here
WARNING: Much of the information in this wiki is out of date. We are in the process of moving things to readthedocs
- Project Introduction
- Neo4j::ActiveNode
- Neo4j::ActiveRel
- Search and Scope
- Validation, Uniqueness, and Case Sensitivity
- Indexing VS Legacy Indexing
- Optimized Methods
- Inheritance
- Core: Nodes & Rels
- Introduction
- Persistence
- Find : Lucene
- Relationships
- Third Party Gems & extensions
- Scaffolding & Generators
- HA Cluster