cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

How to get location of Neo4j 'imports' folder of a DB programmatically?

shern2
Node Link

Hi,

I am using Neo4j Desktop 1.3.11 on Windows.
Am using apoc.export.csv.query() to get my query results via py2neo. This outputs the csv file to the "import" folder of the DB.

Understand it is possible to navigate to the DB's "import" folder by clicking the 'Open Folder' button in Neo4j Desktop. However, I would like to do so programmatically, since my program is aware of the DB's name e.g. neo4j-db, instead of manually specifying the DB's folder location, which naming can be quite obtuse e.g. C:\Users\[username]\AppData\Local\Neo4j\Relate\Data\dbmss\dbms-db3c8764-9a9c-xxx

I did a couple of searches on Google as one in this community forum, but didn't find anything that can do that.

Is there a way, perhaps to call the system graph to check the folder path?
Or perhaps I'm asking the wrong qn -> Is there a way to specify an arbitrary location in Windows to output my csv?

1 ACCEPTED SOLUTION

clem
Graph Steward

To be more complete:

Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.import'
RETURN value

value contains the string of the import directory.

You can also set your import directory in configs

  1. Click on the 3 dots next to DB name
  2. Click on settings
  3. search for: dbms.directories.import=
  4. uncomment it and set it:
    dbms.directories.import=ABSOLUTE_DIRECTORY_PATH

Also see:

View solution in original post

5 REPLIES 5

dana_canzano
Neo4j
Neo4j

cypher

Call dbms.listConfig();

Should list all config parameters and values. You should be able to get import dir from here

clem
Graph Steward

To be more complete:

Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.import'
RETURN value

value contains the string of the import directory.

You can also set your import directory in configs

  1. Click on the 3 dots next to DB name
  2. Click on settings
  3. search for: dbms.directories.import=
  4. uncomment it and set it:
    dbms.directories.import=ABSOLUTE_DIRECTORY_PATH

Also see:

Hi,

Slight tweak to the solution. This call just produces the relative path of the import folder.

Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.import'
RETURN value

The returned values is "import" which is probably not the intent of the request which I take to need the full path.

This returns the full path:

Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.neo4j_home'
RETURN value

and since the folder structure is fixed by the database creation process and the import folder name is "import" so that needs to be added to the end of the returned string.
So this is where I ended up with

def get_import_path(tx):
    result= tx.run("Call dbms.listConfig() YIELD name, value WHERE name='dbms.directories.neo4j_home' RETURN value")
    return [record["value"] for record in result]

with driver.session() as session:
    Neo4JImport = session.read_transaction(get_import_path)[0]+'/import'
driver.close()
Neo4JImport

Andy

For Version 5.1.0 we should use server.directories.neo4j_home instead of home.directories.neo4j_home

cdibble
Node

This solution seems like it may evolve over time. I found a working solution for v1.5.4 by investigating the configs with this query

CALL dbms.listConfig()
YIELD name, value
WHERE name CONTAINS 'import'
RETURN name, value
ORDER BY name
LIMIT 40;

And that led me to the name of the config at this time. So this gives me the location of the local import directory in one shot:

CALL dbms.listConfig()
YIELD name, value
WHERE name = 'server.directories.import'
RETURN value