jsonneo4jcypherneo4j-apoc

Import strings from Neo4j json dump


Say I populate a Neo4j graph as follows:

CREATE (n:Person {name: 'Andy', title: 'Developer'})
CREATE (n:Person {name: 'Betty', title: 'Developer'})

And I dump the contents Neo4j to a json file as follows:

call apoc.export.json.all("dump.json",{useTypes:true})

I would like to import the contents of that json file into a second database instance. I am aware I can import with:

call apoc.import.json("dump.json")

But in my situation I will have the contents of the file in memory (it is guaranteed to not be very large) and cannot load the file from the filesystem. How can I import those lines into the second instance? I don't see a way to do this with apoc.import. Perhaps the way to do this to somehow use apoc.convert.fromJsonList? Am I missing a straightforward way to import these lines?


Solution

  • You can still use APOC export and stream the results so that you can either import it via cypher-shell, or if you do not have access to it, using the Neo4j browser.

    Example:

    To import via cypher-shell -

    CALL apoc.export.cypher.all(null, {
        batchSize: 5,
        streamStatements: true,
        format: "cypher-shell",
        useOptimizations: {type: "UNWIND_BATCH", unwindBatchSize: 5}
    })
    YIELD nodes, relationships, properties, cypherStatements
    RETURN nodes, relationships, properties, cypherStatements;
    
    

    To import via Neo4j browser -

    CALL apoc.export.cypher.all(null, {
        format: "plain",
        useOptimizations: {type: "UNWIND_BATCH", unwindBatchSize: 20}
    })
    YIELD file, batches, source, format, nodes, relationships, properties, time, rows, batchSize
    RETURN file, batches, source, format, nodes, relationships, properties, time, rows, batchSize;