Krishna Shetty
Krishna Shetty

Reputation: 1441

What is the best way to store array of strings as node property in Neo4j

I have a requirement in which a property key can contain multiple values. How do I store them as property in Neo4j?

Ex: Person node has properties like: 'name', 'age' and 'interests' The 'interests' property can can contain more than one strings(array of strings).

What is the best approach to store 'interests'? I think I don't want to complicate this by adding more nodes. Instead I want to keep all properties in the same Person node.

Also, it will be good if I can search a Person node by any one item in the 'interests' property.

Store as one string separated by some special chars? Store as array of strings for a property? if so how do I do this?

Thanks

Upvotes: 12

Views: 18181

Answers (1)

Brian Underwood
Brian Underwood

Reputation: 10856

You can store an array of strings as a property and that's what I might suggest if you want to simply see a list of interests when working with a particular Person node:

http://neo4j.com/docs/stable/rest-api-property-values.html#_arrays

If you want to look up people by interests, however, I would strongly suggest thinking about storing them as nodes. With the MERGE cypher command it can be quite easy to manage them, and it should be more performant.

Upvotes: 5

Related Questions