Exception: org.neo4j.driver.exceptions.ClientException: Invalid input 'ConfigNode': expected an identifier (line 1, column 86 (offset: 85)) "WITH $batch AS document UNWIND document.data AS data FOREACH (node in data| CREATE(m:'ConfigNode') SET m = node )"

Cypher Query:

JSON:

{"data":[{"uuid":"4567-c102-47ft-a87786876","name":"address 1"},{"uuid":"6432dd4d-8a43-4471-bbbb-5a9f47dac6f7","name":"address Group 1"},{"uuid":"6511a9ee-a37e-4ead-a71d-dde04394c3cc","name":"address 2"},{"uuid":"1234567-a37e-4ead-a71d-1234567","name":"Security Rule 1"},{"uuid":"PolicyA-a37e-4ead-a71d-PolicyA","name":"PolicyA 2"},{"uuid":"Policy B-a37e-4ead-a71d-PolicyB","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-PolicyC","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy1","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy2","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy3","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy4","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy5","name":"PolicyA 2"}]}

Query:

    String q3 = "WITH $batch AS document " +
                "UNWIND document.data AS data " +
                "FOREACH (node in data| CREATE(m:'ConfigNode') SET m = node )";

    Map<String, Object> parameters = new HashMap<String, Object>();
    Gson gson = new Gson();
    String json = "{\"data\":"+ gson.toJson(nodes) +"}";

    try (Session session = getWriteTenantDBSession(driver, tenantId)) {
            session.run(q3, parameters);
        }catch(Exception e){
            // log.error("Unable to create node due to exception {}", e.fillInStackTrace());
            e.printStackTrace();
            throw new UnableToSupportOpException("Unable to create node due to exception:"+e.getLocalizedMessage());
        }

1

There are 1 best solutions below

0
On BEST ANSWER

You don't need the quotes for ConfigNode. Also, you don't need the UNWIND because you are already doing a FOREACH loop. UNWIND will do a loop on each item in data (json)

NEW:
    String q3 = "WITH $batch AS document " + 
                "FOREACH (node in data| CREATE(m:ConfigNode) SET m = node )";
OLD:
    String q3 = "WITH $batch AS document " +
                "UNWIND document.data AS data " +
                "FOREACH (node in data| CREATE(m:'ConfigNode') SET m = node )";