Stream spanning tree to an output file

I am trying to get the neighbors of a given root node at the n hop distance.

I can use the following query on a small graph, or when the root node has few neighbors.

MATCH (root: Person { Name: "somename" })
CALL apoc.path.spanningTree(root, {
    maxLevel: 3, 
    bfs: true, 
    labelFilter: 'Person'
}
YIELD path
WITH 
    root, 
    nodes(path) AS pathNodes, 
    relationships(path) AS pathRels
RETURN 
    [root] AS root, 
    [n IN pathNodes WHERE n <> root] AS nodes, 
    pathRels AS relationships

However, when the root node has many neighbors at n hop distance (hundreds of millions), I run into out-of-memory related issues.

I need all the neighbors, hence, I do not limit the output size.

I was wondering if there is any way of streaming the neighbors of a given root node at n hop distance to an output file, such that they are serialized to a file as they are found instead of being collected in the memory.

Is your server configured to handle millions of neighbours? How much RAM do you have?

You can start by trying running a cli, rather than the browser:

query.cypher:

MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
RETURN p.name, m.title LIMIT 10;

then you can run a command line:

$ cypher-shell -u neo4j -p "password" < query.cypher > output.file

I'm running from CLI. That won't answer my question. I need neighbors at n hop distance. As I said, I'm looking for options to stream to a file.

output.file is a stream to a file ?