Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Expect disruption to service on Thursday, Feb. 9!

How can we update existing map in sdn5 using cypher query

Node Link

How can we update existing map in sdn5 using cypher query

like we have a field in my node


I just want it to be

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

How can we do that?




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

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

There can be several options like prefix etc.

Node Link

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

Node Link

@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.

Node Link

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.