Adding new properties to an existing map

28 views
Skip to first unread message

bi...@levelstory.com

unread,
Apr 7, 2015, 3:24:26 PM4/7/15
to ne...@googlegroups.com
Is there any way to add additional properties to an existing Map object?

I thought I could use SET, but it doesn't work on maps:

WITH {a: "foo"} AS result
SET result.b = "bar"
RETURN result

Type mismatch: expected Node or Relationship but was Map (line 1, column 31)

Because of this, I'm currently doing this everywhere which makes the queries hard to read:

WITH {a: "foo"} AS result
WITH {a: result.a, b: "bar"} AS result
RETURN result


Thanks,
bill 

Michael Hunger

unread,
Apr 7, 2015, 5:09:27 PM4/7/15
to ne...@googlegroups.com, Stefan Plantikow
Hey Bill,

interesting what's your use-case for this?

Thanks so much,

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bi...@levelstory.com

unread,
Apr 7, 2015, 5:39:16 PM4/7/15
to ne...@googlegroups.com, stefan.p...@neotechnology.com
Hi Michael,

In order to reduce the number or rows resulting from complex queries, I bundle up the results of sub queries into a Map object.  I then return a collection of Map objects which can then be easily converted into Go structs.  I believe that you were the one that suggested this approach to me.

Here is how I am doing most of my queries:

  MATCH (f:file {id: "foobar"})
  WITH f, {accessedrole: "", accessedby: ""} AS r

  OPTIONAL MATCH (f)-[:CREATED]->(a:activity)
  WITH f, {
    accessedrole: r.accessedrole, accessedby: r.accessedby,
    createdat: a.createdat, createdby: {id: a.contactid, object: "contact"}} AS r

  OPTIONAL MATCH (f)-[:HISTORY]->(a:activity)
  WITH f, {
    accessedrole: r.accessedrole, accessedby: r.accessedby,
    createdat: r.createdat, createdby: r.createdby,
    updatedat: a.createdat, updatedby: {id: a.contactid, object: "contact"}} AS r

  OPTIONAL MATCH (f)-[:TAG]->(x)
  WITH f, COLLECT(x) AS xs, r
  WITH f, {
    accessedrole: r.accessedrole, accessedby: r.accessedby,
    createdat: r.createdat, createdby: r.createdby,
    updatedat: r.updatedat, updatedby: r.updatedby,
    tags: [x IN xs | {id: x.id, object: x.object, name: x.name}]
    } AS r

  RETURN COLLECT({
    id: f.id, object: f.object, projectid: f.projectid,
    no: f.no, name: f.name, description: f.description, url: f.url,
    mime: f.mime, thumbnail: f.thumbnail, size: f.size,
    accessedrole: r.accessedrole, accessedby: r.accessedby,
    createdat: r.createdat, createdby: r.createdby,
    updatedat: r.updatedat, updatedby: r.updatedby,
    tags: r.tags
  }) AS r

Michael Hunger

unread,
Apr 7, 2015, 6:14:50 PM4/7/15
to ne...@googlegroups.com, Stefan Plantikow
Hmm,

what you could do instead of modifying the map in-place to create the new map with the additional data around the original one:

e.g.

WITH {a: "foo"} AS result
RETURN {inner: result, b: "bar"} AS result


We're also looking into a feature like:

SET map.key = value

But I can't give any timeline for that right now.

Cheers, Michael

bi...@levelstory.com

unread,
Apr 7, 2015, 6:32:52 PM4/7/15
to ne...@googlegroups.com, stefan.p...@neotechnology.com
Yes, I thought about that but then I would need to unpack everything again before I return the results.  Being able to do SET map.key would be ideal, I guess I'll just wait until that becomes available.  

Jason Brumwell

unread,
Jul 1, 2016, 10:45:43 AM7/1/16
to Neo4j, stefan.p...@neotechnology.com
I also would love this feature :)

Michael Hunger

unread,
Jul 3, 2016, 10:15:24 AM7/3/16
to ne...@googlegroups.com, stefan.p...@neotechnology.com
You can do it with the apoc procedures

There is eg apoc.map.setKey

Von meinem iPhone gesendet
Reply all
Reply to author
Forward
0 new messages