I want to create labels for nodes and relationships in a Neo4j database, without any property constraints. Specifically, I want to create a "Person" label for nodes and a "LIKED" label for relationships, but I don't need any mandatory properties like p.name or l.when.
The Cypher queries you provided:
CREATE CONSTRAINT FOR (p:Person) REQUIRE p.name IS UNIQUE
CREATE CONSTRAINT FOR ()-[l:LIKED]-() REQUIRE l.when IS NOT NULL
These create constraints that require nodes with the Person label to have a unique p.name property, and relationships with the LIKED label to have a non-null l.when property.
Instead, I just want to create the labels themselves, without any property constraints. Is there a way to create labels in Neo4j without requiring any mandatory properties?
Yes. You are not required to set any properties on nodes nor relationships if you don’t explicitly require any through constraints like you showed. Don’t create those constraints and you will be fine.
Thank you always for your responses. I see, the Cypher query you mentioned above is indeed a Cypher query for creating constraints.
For example, if I use the Cypher query CREATE (n:MODE), it would create a node with the label MODE. However, I just want to create the label MODE without creating any nodes.
I could create a MODE node and then delete it, but is there a smarter Cypher query to create only the label?
I don’t understand why you would want to do that. A new label will be created when you create a node with for the first time. If you have no nodes in your database to search for, what is the need for a label.
I want to work on creating a knowledge graph collaboratively with multiple people using Bloom. However, some people may not be able to use cypher queries. Those people plan to manually create nodes and relations in Bloom. But in Bloom, you cannot create a node unless a label for it is already registered. So we would need to create just the labels first.
I can create Categories, but you can't execute "Create node" unless a label is already registered.
I was able to create a category called "TEST", but since I can't add labels, "TEST" doesn't show up as an option when trying to create a new node.
Ok, then go into browser, create a node for each label, then delete the nodes. You only need to do it once and it will not take too long. I would not worry about optimization or what is easier.
You might try the following command and see if that creates the label in a way that Bloom will like it. In our permissioning strategy we do not give accounts naming permissions so we can avoid misspelled labels, relationships and properties getting into the database by accident.
CALL db.createLabel("TEST");
1 Like