Lists

In this lesson, you will learn about:

  • Multi-value properties and lists

  • How to transform a string value into a list

  • The split function

What is a Multi-value property?

A multi-value property is a property that can hold one or more values. Neo4j represents this type of data as a list (or "StringArray").

All values in a list must have the same data type. For example:

  • ["Apple", "Banana, "Orange"]

  • [100, 55, 4]

The movies.csv data file contains multi-value properties, including:

  • countries - the countries which produced the movie

  • languages - the languages spoken in the movie

Find the countries and languages data in the movies.csv file. You will see that each property contains a list of values separated by a | character. For example:

USA|France|Italy|Germany
English|Mandarin|Russian

Split the data into a list

The split function will transform a string value into a list. The split function takes two arguments:

  • The string to split

  • The character to split on

This updated Movie import creates a list of countries by using the split function:

cypher
LOAD CSV WITH HEADERS
FROM 'https://data.neo4j.com/importing-cypher/movies.csv'
AS row
MERGE (m:Movie {movieId: toInteger(row.movieId)})
SET
m.tmdbId = toInteger(row.movie_tmdbId),
m.imdbId = toInteger(row.movie_imdbId),
m.released = date(row.released),
m.title = row.title,
m.year = toInteger(row.year),
m.plot = row.plot,
m.budget = toInteger(row.budget),
m.imdbRating = toFloat(row.imdbRating),
m.poster = row.poster,
m.runtime = toInteger(row.runtime),
m.imdbVotes = toInteger(row.imdbVotes),
m.revenue = toInteger(row.revenue),
m.url = row.url,
m.countries = split(row.countries, '|')

The statement sets the countries property as a list by splitting the data from the CSV file by the | character.

Run the query and inspect the countries property data by writing a MATCH query to return the data.

You can query data in a list using the IN operator. For example, finding all the movies where "French" is a listed language.

cypher
MATCH (m:Movie)
WHERE "France" IN m.countries
RETURN m

Check Your Understanding

List types?

True or False - values in a list can be of different data types.

  • ❏ True

  • ✓ False

Hint

This list would not be valid.

[100, "Banana", 4.1]

Solution

The statement is False - All values in a list must have the same data type.

Summary

In this lesson, you learned about multi-value properties, lists and how to create them using the split function.

In the next lesson, you will update the Cypher statement to split the languages property into a list.