Using Parameters

In the previous challenge, you identified how to set the name parameter within a Neo4j Browser session.

In this challenge, you will need to execute the following query to find all movies acted in by an Actor with a name starting with Tom, and that also have the value UK within the countries array on the movie.

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, coutry

To complete this challenge, complete the following steps:

1. Set the name Parameter

Using the same format as the previous lesson, set the name parameter to Tom.

2. Set the country Parameter

Set the country parameter to UK.

3. Execute the Query

Hit the Run in Sandbox button to the top right of the query window below to execute the query.

cypher
Run this 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

You should see a message at the bottom of the screen in the following format:

Started streaming XXX records after Y ms and completed after Z ms.

1. 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:

cypher
Using the :params command
:params {name: "Tom", country: "UK"}

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.

Once you have entered the answer, click the Try Again button below to continue.

Solution

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.

The correct answer is 39

Once you have entered the answer, click the Try Again button below to continue.

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.

Chatbot

Hi, I am an Educational Learning Assistant for Intelligent Network Exploration. You can call me E.L.A.I.N.E.

How can I help you today?