Search code examples
neo4jjsoncpp

Neo4j and json creating multiple nodes with multiple params


I tried many things but of no use. I have already raised a question on stackoverflow earlier but I am still facing the same issue. Here is the link to old stackoverflow question creating multiple nodes with properties in json in neo4j

Let me try out explaining with a small example This is the query I want to execute

{
   "params" : {
      "props" : [
         {
            "LocalAsNumber" : 0,
            "NodeDescription" : "10TiMOS-B-4.0.R2 ",
            "NodeId" : "10.227.28.95",
            "NodeName" : "BLR_WAO_SARF7"
         }
      ]
   },
   "query" : "MATCH (n:Router) where n.NodeId = {props}.NodeId  RETURN n"}

For simplicity I have added only 1 props array otherwise there are around 5000 props. Now I want to execute the query above but it fails. I tried using (props.NodeId}, {props[NodeID]} but everything fails. Is it possbile to access a individual property in neo4j?

My prog is in c++ and I am using jsoncpp and curl to fire my queries.


Solution

  • If you do {props}.nodeId in the query then the props parameter must be a map, but you pass in an array. Do

    "props" : {
            "LocalAsNumber" : 0,
            "NodeDescription" : "10TiMOS-B-4.0.R2 ",
            "NodeId" : "10.227.28.95",
            "NodeName" : "BLR_WAO_SARF7"
     }
    

    You can use an array of maps for parameter either with a simple CREATE statement.

    CREATE ({props})
    

    or if you loop through the array to access the individual maps

    FOREACH (prop IN {props} | 
        MERGE (i:Interface {nodeId:prop.nodeId})
          ON CREATE SET i = prop
    )