Ankit Gupta
Ankit Gupta

Reputation: 2599

Data model in neo4j

I am using neo4j in my application where i have data model something like:

There are many type of resources like car,truck,room,computer,chair etc,these resources have some properties in common but other properties are different for each type of resource.

So i can model resources in two ways :

  1. All should be considered as Resource(Node-Label) and will have a property 'type' which can have value like car,truck etc.

  2. Each type should be considered as node label and will have its own properties only.

Which one is better?

Upvotes: 0

Views: 69

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39915

You can also assign multiple labels on e.g. a Car:

CREATE (mercedes:Car:Resource {color:'red', ...})

This way you'll find the node when looking for generic resources as well as when looking specifically for cars.

Using a type property is a anti-pattern in most cases due to the invention of labels in Neo4j 2.0.

Upvotes: 3

Related Questions