Neocons Cypher tquery and accessing values from keys

19 views
Skip to first unread message

Ben McFerren

unread,
Sep 21, 2015, 4:43:10 PM9/21/15
to clojure-neo4j

After calling neo4j with neocons (cy/tquery conn node-query {:_nodeid _nodeid}), how do you perform accessing functions to get property values from the keys that are returned from the neo4j datastore response?

For example if this object was the response from the neo4j datastore, what neocons syntax do I use to access the value stored in key "attributes"?



[ {
  "id": "letter-a",
  "name": "Letter A",
  "attributes": [ ... ]
}]



Currently I can only get so far as (first _response) but (get-in (first _response) [:attributes]) is giving me back nil



Here is the cypher query string I use as an argument to invoke the tquery function:


(def node-query "MATCH (n)-[attributelist:RELATIONSHIPTYPE]->(target)
                 RETURN n.id          AS id, 
                        n.name        AS name, 
                        COLLECT({
                          target    : target.id
                        })            AS attributes;")



I don't understand what type of variable tquery returns? It looks like this object when the client displays it all the way in the browser:


[
  {
    "id": "node-999990a0a0a0sa0",
    "name": "Node Name",
    "attributes": [
      {
        "target": "node-id-one"
      },
      {
        "target": "node-id-two"
      },
      {
        "target": "node-id-two"
      },
      {
        "target": "node-id-two"
      },
      {
        "target": "node-id-three"
      }
    ]
  }
]



But I want to intercept what is returned from the tquery before the clojure server delivers it to the client and I want to manipulate the array value of the key "attributes" so I can run a reduce (tally) report before I deliver a rebuilt object response to the client.



{
    ...
    "attributes" : {
        "node-id-one"     : 1,
        "node-id-two"     : 3,
        "node-id-three"   : 1
    }
}



But I am having trouble because I do not know the syntax to access the "attributes" key from the object that is returned from the tquery


I am very grateful for help you could offer.


-Ben


Michael Klishin

unread,
Sep 21, 2015, 4:52:03 PM9/21/15
to clojur...@googlegroups.com
2015-09-21 23:43 GMT+03:00 Ben McFerren <ecomb...@gmail.com>:
[ {
  "id": "letter-a",
  "name": "Letter A",
  "attributes": [ ... ]
}]



Currently I can only get so far as (first _response) but (get-in (first _response) [:attributes]) is giving me back nil

Most likely because :attributes and "attributes" are not the same value.

Try (get-in _response [0 "attributes"]). This is a general Clojure question, nothing Neocons-specific.
--
Reply all
Reply to author
Forward
0 new messages