cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How can we update existing map in sdn5 using cypher query

How can we update existing map in sdn5 using cypher query

like we have a field in my node

output:{"A":"B"}

I just want it to be

output:{"A":"B", "C":"D"}

How can we do that?

6 REPLIES 6

Hi,

Could you please be more specific how this field is on a node?
A Map by itself is not a valid Cypher type AFAIK.

Or do you mean a Map in the domain model? You could use @Properties, so there is no need for custom Cypher.
It would look like

@NodeEntity
public class EntityWithMap {
  // id etc.
  @Properties
  private Map<String, String> output;
}

There can be several options like prefix etc.

https://neo4j.com/docs/ogm-manual/current/reference/#reference:annotating-entities:node-entity:dynam...

Yes I am using @properties only what I actually mean is that I already have this field in my node and now I want to update this field which is a map itself

@gerrit.meier I am using the map and @properties only but I have a requirement to update that field asynchronously via many threads and data should not be overlapped so I need to do something we are currently doing in Postgres like

data = data || jsonb_build_object(:key, :value\:\:jsonb)

We are doing this in native query now we want to do the same thing in neo4j and we are using the standard Java MAp in domain model with @Properties annotation.

Need guidance over how we need to get it done.

You mean in Neo4j-OGM, right? Or what is the native query referring to?
As far as I understand you (hopefully correct), you create a NodeEntity just for handling a property map that you are heavily updating or at least checking(?) I am really not sure right now if using an object graph mapper really helps you with this special use case. It seems that it is only a wrapper around the map to "hold" the data.

We are adding some more values to the map and since it is in an asynchronous manner we just want to make it directly updating the database using native query like

Let's suppose we have Map a = {'a':'a'} in our database and now 2 threads are updating this map with 'b':'b' and 'c':'c'

So what I want is to have all the data in the database and no overwriting should happen.

Also, this @properties field is one of the node element and not the only one.

I would suggest to activate optimistic locking in this case.
With the (maybe to naive) logic, that if an update fails due to optimistic locking exception, you would then fetch it from the database first and merge / add the properties before storing it again.