Operators in Neo4j
Operators in Neo4j are used for performing logical, arithmetic, and comparison operations on values stored in nodes, properties, or variables. Operators enable users to execute complex queries and perform computations to generate useful results.
Syntax
Operators in Neo4j follow the same syntax as those in other programming languages. Some of the commonly used operators include:
+
Addition-
Subtraction*
Multiplication/
Division%
Modulo=
Equal to<>
Not equal to<
Less than>
Greater than<=
Less than or equal to>=
Greater than or equal to
Example
Consider the following graph:
(:Person{name:"Alice", age:35})-[:FRIEND_OF]->(:Person{name:"Bob", age:42})
To retrieve all nodes for persons who are older than 40, the following Cypher query can be used:
MATCH (p:Person)
WHERE p.age > 40
RETURN p
This will return the following output:
╒═══════════════════════════════════════════════════════════╕
│"p" │
╞═══════════════════════════════════════════════════════════╡
│{"name":"Bob","age":42} │
╘═══════════════════════════════════════════════════════════╛
Explanation
In the example above, the WHERE
clause uses the greater than >
operator to filter out only those Person
nodes with age greater than 40. This results in only one matching Person
node being returned.
Use
Operators in Neo4j can be used for performing logical, arithmetic, and comparison operations on values stored in nodes, properties, or variables. They are particularly useful when you want to execute complex queries and perform computations to generate useful results.
Important Points
- Operators in Neo4j follow the same syntax as those in other programming languages.
- The
WHERE
clause is used in Cypher queries to filter out nodes based on specific conditions. - Cypher supports a wide range of operators, including mathematical, logical, and comparison operators.
- Multiple operators can be used in a single Cypher query to perform complex computations and generate useful results.
Summary
Operators in Neo4j are used for performing logical, arithmetic, and comparison operations on values stored in nodes, properties, or variables. They enable users to execute complex queries and perform computations to generate useful results. Cypher supports a wide range of operators, including mathematical, logical, and comparison operators. Multiple operators can be used in a single Cypher query to perform complex computations and generate useful results.