15

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?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460

3 Answers3

11

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!

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
  • If you want spaces, you can. You need to enclose the relationship type in backticks though. The syntax is often used in MySQL for object names with spaces. – ADTC May 12 '16 at 17:22
11

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:

P. Jausions
  • 131
  • 1
  • 3
0

Could be easier to bring everything to upper case or lower case using LOWER() and UPPER() string functions

1- Let's suppose I have a node with a property name = 'name' in lower case, to find it you need to match againt the exact string

Query:
CYPHER 2.0
START n=node(*)
WHERE n.name= "name"
RETURN id(n)

id(n)
5

Query took 3 ms and returned 1 rows.

otherwise you will not find it :

Query:
CYPHER 2.0
START n=node(*)
WHERE n.name= "Name"
RETURN id(n)


Query took 4 ms and returned no rows.

But, we can match it using string function LOWER():

CYPHER 2.0
START n=node(*)
WHERE n.name= LOWER("Name")
RETURN id(n)

id(n)
5

Query took 4 ms and returned 1 rows.

2- With node property entered with arbitrary string case ex: "NaMe", to match against :

START n=node(*)
WHERE LOWER(n.name)= "name"
RETURN id(n)

id(n)
8

Query took 5 ms and returned 1 rows.
AJN
  • 1,196
  • 2
  • 19
  • 47