Using Parameters

In the previous challenge, you learned how to set a parameter.

In this challenge, you will need to create to create multiple parameters to run this query:

cypher
Your Query
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE p.name STARTS WITH $name
AND $country IN m.countries
RETURN p.name AS actor,
m.title AS title

If you run this query without setting any parameters, you will receive an error:

Expected parameter(s): name, country

To complete this challenge, complete the following steps:

  1. Set the name parameter to Tom.

  2. Set the country parameter to UK.

  3. Execute the Query

    cypher
    MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
    WHERE p.name STARTS WITH $name
    AND $country IN m.countries
    RETURN p.name AS actor,
    m.title AS title

How many records?

How many records are returned for actors with a name starting with Tom and with UK in the list of countries on the Movie node.

  • ✓ 39

Hint

You can set both parameters in one command using the :params command. The syntax is:

cypher
:params {key1: 'value1', key2: 'value2'}

Solution

The answer is 39.

You can set the parameters using the following command:

cypher
:params {name: 'Tom', country: 'UK'}

Summary

In this challenge, you used multiple parameters to affect the results of a Cypher statement.

In the next lesson, you will see some application code that uses parameters in Cypher.