Reputation: 615
In neo4j, i want to filter and collect data by foreach statement.
Example
My user case with mysql.
users = User ->findAll();
data = array();
foreach(users as user){
profile = Profile:findBy(user);
if(user.age > 20 and profile.company is empty)
data[] = user;
}
return data
thank
Upvotes: 1
Views: 197
Reputation: 67044
In Cypher, this is roughly equivalent to your code:
MATCH (u:User)-[:HAS_PROFILE]->(p:Profile)
WHERE u.age > 20 AND (p.company IS NULL OR p.company = "")
RETURN u;
This query assumes you have nodes labelled User
(with at least an age
property) and Profile
(with a company
property that is either optional or that may contain an empty string), connected by HAS_PROFILE
relationships.
Upvotes: 1