Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

neo4j

cypher

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

like image 508
Krishna Shetty Avatar asked Apr 19 '15 14:04

Krishna Shetty


People also ask

What is the correct syntax to create a node with a property in Neo4j?

In Neo4j, properties are the key-value pairs which are used by nodes to store data. CREATE statement is used to create node with properties, you just have to specify these properties separated by commas within the curly braces "{ }". Syntax: CREATE (node:label { key1: value, key2: value, . . . . . . . . . })

What are the property values in Neo4j?

Property types. Integer, Float, String, Boolean, Point, Date, Time, LocalTime, DateTime, LocalDateTime, and Duration.

What are property keys in Neo4j?

A graph key is a property or set of properties which help you to identify a node or relationship in a graph. They are frequently used as a starting point for a graph traversal, or used as a condition to constrain.

Which Cypher statement returns the keys used for properties on nodes and relationships?

Return all elements When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. Node[0]{name:"A",age:55,happy:"Yes!"}


1 Answers

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.

like image 85
Brian Underwood Avatar answered Nov 17 '22 00:11

Brian Underwood