Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-14-2020 08:00 AM
I cannot get User data, the very first step in this training. What ever I do, I get NumReviews 0. In the console there is an message Error, but the comment is empty. Any ideas?
Srdjan
Solved! Go to Solution.
08-14-2020 08:03 AM
It looks that I solved this myself 🙂 It was puzzling for me why this simple step is not working, so I went through files and found the query that was supposed to get things done:
It is in exercises/exercise0.js:
export const FETCH_USER_INFO_QUERY = `
MATCH (u:User {id: $userId})
MATCH (u)-[:WROTE]->(r:Review)
WITH u, avg(r.stars) AS averageStars
MATCH (u)-[:WROTE]->(:Review)-[:REVIEWS]->(:Business)-[:IN_CATEGORY]-(c:Category)
WITH *, c.name AS category, COUNT(*) AS num ORDER BY num DESC
RETURN u {
.name,
numReviews: toFloat(SIZE((u)-[:WROTE]->(:Review))),
categories: COLLECT(category)[..5],
averageStars
} AS userInfo
`;
I tried this query in Neo4j browser and got error for variable u and averageStars, and if you look closely averageStars is not in the last WITH. When I did this it worked. I thought that WITH * was supposed to return all previous variables?:
export const FETCH_USER_INFO_QUERY = `
MATCH (u:User {id: $userId})
MATCH (u)-[:WROTE]->(r:Review)
WITH u, avg(r.stars) AS averageStars
MATCH (u)-[:WROTE]->(:Review)-[:REVIEWS]->(:Business)-[:IN_CATEGORY]-(c:Category)
WITH u, averageStars, c.name AS category, COUNT(*) AS num ORDER BY num DESC
RETURN u {
.name,
numReviews: toFloat(SIZE((u)-[:WROTE]->(:Review))),
categories: COLLECT(category)[..5],
averageStars
} AS userInfo
`;
Srdjan
08-14-2020 08:03 AM
It looks that I solved this myself 🙂 It was puzzling for me why this simple step is not working, so I went through files and found the query that was supposed to get things done:
It is in exercises/exercise0.js:
export const FETCH_USER_INFO_QUERY = `
MATCH (u:User {id: $userId})
MATCH (u)-[:WROTE]->(r:Review)
WITH u, avg(r.stars) AS averageStars
MATCH (u)-[:WROTE]->(:Review)-[:REVIEWS]->(:Business)-[:IN_CATEGORY]-(c:Category)
WITH *, c.name AS category, COUNT(*) AS num ORDER BY num DESC
RETURN u {
.name,
numReviews: toFloat(SIZE((u)-[:WROTE]->(:Review))),
categories: COLLECT(category)[..5],
averageStars
} AS userInfo
`;
I tried this query in Neo4j browser and got error for variable u and averageStars, and if you look closely averageStars is not in the last WITH. When I did this it worked. I thought that WITH * was supposed to return all previous variables?:
export const FETCH_USER_INFO_QUERY = `
MATCH (u:User {id: $userId})
MATCH (u)-[:WROTE]->(r:Review)
WITH u, avg(r.stars) AS averageStars
MATCH (u)-[:WROTE]->(:Review)-[:REVIEWS]->(:Business)-[:IN_CATEGORY]-(c:Category)
WITH u, averageStars, c.name AS category, COUNT(*) AS num ORDER BY num DESC
RETURN u {
.name,
numReviews: toFloat(SIZE((u)-[:WROTE]->(:Review))),
categories: COLLECT(category)[..5],
averageStars
} AS userInfo
`;
Srdjan
08-14-2020 09:01 AM
WITH * should work.
Elaine
All the sessions of the conference are now available online