cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to auto-import csv content into Neo4j

Hi! We are trying to receive a CSV file from frontend and create nodes from the CSV content. How do we get the neo4J to load the CSV code from javascript automatically when we receive a new CSV-file?

Currently we are thinking something like this to receive the file in frontend:

import fileUpload from "express-fileupload";
app.use(fileUpload());

//Upload endpoint
app.post('/upload', (req, res) => {
  if(req.files === null){
    return res.status(400).json({ msg: 'No file uploaded'});
  }
  const file = req.files.file;
  file.mv(${__dirname}/client/public/uploads/${file.name}, err => {
    if(err){
      console.error();
      return res.status(500).send(err);
    }
    res.json({ fileName: file.name, filePath: `/uploads/${file.name}`});
  })
})
1 ACCEPTED SOLUTION

You'll need to trigger a Cypher command, somehow. That could be an API method you add to Neo4j via a plugin. Though that's much trickier than you might think (I'm almost ready to publish an open plugin like this). Before you go too deep, check the import guide:

Your options:

  • Plugin to tweak the api, and handle the upload.
  • Driver on the server-side. Running Node.js as a middleman to provide the resource (server-side to handle the POST request) to receive and save the csv, then trigger the Cypher import command.
  • Use the Bolt driver in the client, to trigger the Cypher import command.
    • You'd have to build a way to make the CSV file accessible to Neo4j. That can be a url to the file (with some Neo configuration tweaks), or the file can be put in the $NEO_HOME/import directory.
    • Alternatively, you could parse the CSV in the client, and convert it into a set of native Cypher commands that would not require uploading the file.

Cypher IMPORT

The neo4j-javascript driver (docs) (github) can be used server-side, or client-side. There are two Cypher utilities that can import CSV:

However, both of these utilities require the file to already exist somewhere Neo can access.

Client Affect

If you're only building a javascript client, and you want the user to be able to create and upload the csv, then you're going to have to work some magic, and you have a few options:

  • Use a intermediary storage location, have the client send the CSV there, resulting in a URL that Neo4j can access, then run the Cypher import command through the neo4j-javascript driver.
  • Parse the csv in the client, and built the Cypher commands to MERGE/CREATE Nodes.

View solution in original post

3 REPLIES 3

You'll need to trigger a Cypher command, somehow. That could be an API method you add to Neo4j via a plugin. Though that's much trickier than you might think (I'm almost ready to publish an open plugin like this). Before you go too deep, check the import guide:

Your options:

  • Plugin to tweak the api, and handle the upload.
  • Driver on the server-side. Running Node.js as a middleman to provide the resource (server-side to handle the POST request) to receive and save the csv, then trigger the Cypher import command.
  • Use the Bolt driver in the client, to trigger the Cypher import command.
    • You'd have to build a way to make the CSV file accessible to Neo4j. That can be a url to the file (with some Neo configuration tweaks), or the file can be put in the $NEO_HOME/import directory.
    • Alternatively, you could parse the CSV in the client, and convert it into a set of native Cypher commands that would not require uploading the file.

Cypher IMPORT

The neo4j-javascript driver (docs) (github) can be used server-side, or client-side. There are two Cypher utilities that can import CSV:

However, both of these utilities require the file to already exist somewhere Neo can access.

Client Affect

If you're only building a javascript client, and you want the user to be able to create and upload the csv, then you're going to have to work some magic, and you have a few options:

  • Use a intermediary storage location, have the client send the CSV there, resulting in a URL that Neo4j can access, then run the Cypher import command through the neo4j-javascript driver.
  • Parse the csv in the client, and built the Cypher commands to MERGE/CREATE Nodes.

We are thinking of the option:

Use a intermediary storage location, have the client send the CSV there, resulting in a URL that Neo4j can access, then run the Cypher import command through the neo4j-javascript driver.

and sessions would be the container that handles execution of cypher-queries into Neo4J when we drag and drop a CSV?

Hi, I think that an easy solution could be to create a cloud function (for example with Firebase). This function can be triggered when a file is uploaded to storage. This function receives the file, processes and creates the nodes in neo4j. The function will run in background.

https://firebase.google.com/docs/functions/gcp-storage-events