Finding mutual friends with Neo4j

Sally and John are Facebook friends. Now, find out the people who are friends with both Sally and John. This is also known as the mutual friend problem.

In this recipe, you will learn how to find mutual friends between two people.

Getting ready

Perform the following steps to get ready for this recipe:

  1. Install Neo4j on your machine using the recipes from Chapter 1, Getting Started with Neo4j.
  2. Use the following Cypher script to create the dataset for this recipe:
    CREATE
        (bradley:User {name:'Bradley', surname:'Green', age:24, city:'Los Angeles'}),
        (matthew:User {name:'Matthew', surname:'Cooper', age:36, city:'Los Angeles'}),
        (lisa:User {name:'Lisa', surname:'Adams', age:15, city:'New York'}),
     (annie:User {name:'Annie', ...

Get Neo4j Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.