Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the neo4j naming conventions?

Tags:

neo4j

I'm curious about naming conventions in neo4j.

I noticed in their examples that relationship names where capitalized, e.g.

left-[r:KNOWS]->right

Is that the convention? Is neo4j case sensitive in relationship names? Are there other naming conventions around index names and property names?

like image 982
MonkeyBonkey Avatar asked Nov 20 '12 22:11

MonkeyBonkey


People also ask

What are Neo4j labels?

Label is a name or identifier to a Node or a Relationship in Neo4j Database. We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node.

How do you name a relationship in Neo4j?

You cannot rename an already existing relationship. You'd have to run through all relationships, create the new one in parallel (including all properties) and then remove the old one.

What are properties in Neo4j?

Properties are key-value pairs that are used for storing data on nodes and relationships. The value part of a property: Can hold different data types, such as number , string , or boolean .


2 Answers

That is the convention. I personally use lower case relationship types, and yes, it is case-sensitive. With underscores.

Usually, people use underscores for index names as well, and they're usually lower case, and also case-sensitive.

Also, something to remember: if you don't specify direction while creating, the default is left<--right. Not intuitive for me, but now I just specify direction always.

For the properties, I think most people use JSON style conventions: http://google-styleguide.googlecode.com/svn/trunk/jsoncstyleguide.xml#Key_Names_in_JSON_Maps

I've also seen underscores for properties, so I guess it goes either way. Just be consistent!

like image 138
Eve Freeman Avatar answered Sep 26 '22 20:09

Eve Freeman


Yes, the convention for relationship names is to have them ALL_UPPERCASE. All names in Neo4j are case-sensitive (labels, relationships, properties, ...)

Keep in mind that this is a convention, not a requirement. The most important part in any project is consistency. Use a coding style and stick to it throughout!

Neo4j naming convention:

  • Labels: UpperCamelCase (a.k.a. PascalCase)
  • Relationships: CAPITALIZED_WITH_UNDERSCORE
  • Property key names: lowerCamelCase or snake_case

Cypher examples:

CREATE (:Person {name:"Anne"})-[:MANAGES {start_date:20121112}]->(:WorkGroup {name:"Dev"});

Alternatively:

CREATE (:Person {name:"Anne"})-[:MANAGES {startDate:20121112}]->(:WorkGroup {name:"Dev"});

References:

  • The Neo4j Developer Manual
  • The O'Reilly Graph Databases - Neo4j Graph Database
like image 28
P. Jausions Avatar answered Sep 24 '22 20:09

P. Jausions