Storing data as an array/list on neo4j property

ayan_2587 picture ayan_2587 · Sep 24, 2013 · Viewed 11.8k times · Source

I am fairly new to Neo4j and have the following problem at hand. I am trying to develop a social networking site wherein I would like to store the message exchanged between two users on their relationship property. For this, I am trying to store all their messages in the form of array/list on a relationship property. Can you please suggest if Neo4j provides such types of operation.

I would also like to know if I could just insert my message on this relationship property and the array/List updates(i.e adds new message on the next index)

For ex:

User1 -> User2 : Hi, whats up 
User2 -> User1 : Hi, I am in college

So the relationship property stores the message in the form of list such as:
["Hi,Whats up", "Hi, I am in college"]

Something in this manner..... Thanks

Answer

Stefan Armbruster picture Stefan Armbruster · Sep 24, 2013

Neo4j supports array properties, see http://neo4j.com/docs/rest-docs/current/#rest-api-property-values.

However I'm not sure if you're using a good modeling approach here. If you store all the messages in an array you don't have the timeline of the conversation explicit in the graph. Even worse if a User1 sends 2 messages to User2 without a response from User2 in between, you'll don't know any longer who was the sender and receiver.

Therefore think of introducing a node representing a conversation. The conversation is related to two users. Another relationship points to the start (or end) of the message flow within this conversation. The messages itself are linked with NEXT and/or PREVIOUS relationships to each other.