cancel
Showing results for 
Search instead for 
Did you mean: 

Show datatype in neo4j browser?

MPasadu
Node Link

Is there a way to show the datatypes in the neo4j browser?

If a property has a number, you can't see if it is a string or a number. Same with boolean, it just shows "PropertyName: true", and you have no idea if it is a boolean true or a string "true"

Something like "PropertyName [bool]: true" or "PropertyName [number]: 123" would be helpful.

1 ACCEPTED SOLUTION

dana_canzano
Neo4j
Neo4j

Since Neo4j is a schema free database this could be challenging for a given property could actually have different datatypes for multiple nodes. For example creating 3 nodes as follows

neo4j> create (n:MPasadu {id:1});
0 rows available after 413 ms, consumed after another 0 ms
Added 1 nodes, Set 1 properties, Added 1 labels
neo4j> create (n:MPasadu {id:'true'});
0 rows available after 23 ms, consumed after another 0 ms
Added 1 nodes, Set 1 properties, Added 1 labels
neo4j> create (n:MPasadu {id:true});
0 rows available after 26 ms, consumed after another 0 ms
Added 1 nodes, Set 1 properties, Added 1 labels

and running the following will return the datatypes, but note the id property has multiple datatypes


neo4j> match (n:MPasadu) return n.id,apoc.meta.type(n.id);
+-------------------------------+
| n.id   | apoc.meta.type(n.id) |
+-------------------------------+
| 1      | "INTEGER"            |
| "true" | "STRING"             |
| TRUE   | "BOOLEAN"            |
+-------------------------------

Admittedly I might expect in most cases that a given property on a node is generally all the same datatype, i.e. if you had a property named age, 99% of those properties would be a INTEGER datatype. Is there a benefit to having the datatype? for example without the awareness/detail of the datatype does this cause further downstream effect?

View solution in original post

3 REPLIES 3

dana_canzano
Neo4j
Neo4j

Since Neo4j is a schema free database this could be challenging for a given property could actually have different datatypes for multiple nodes. For example creating 3 nodes as follows

neo4j> create (n:MPasadu {id:1});
0 rows available after 413 ms, consumed after another 0 ms
Added 1 nodes, Set 1 properties, Added 1 labels
neo4j> create (n:MPasadu {id:'true'});
0 rows available after 23 ms, consumed after another 0 ms
Added 1 nodes, Set 1 properties, Added 1 labels
neo4j> create (n:MPasadu {id:true});
0 rows available after 26 ms, consumed after another 0 ms
Added 1 nodes, Set 1 properties, Added 1 labels

and running the following will return the datatypes, but note the id property has multiple datatypes


neo4j> match (n:MPasadu) return n.id,apoc.meta.type(n.id);
+-------------------------------+
| n.id   | apoc.meta.type(n.id) |
+-------------------------------+
| 1      | "INTEGER"            |
| "true" | "STRING"             |
| TRUE   | "BOOLEAN"            |
+-------------------------------

Admittedly I might expect in most cases that a given property on a node is generally all the same datatype, i.e. if you had a property named age, 99% of those properties would be a INTEGER datatype. Is there a benefit to having the datatype? for example without the awareness/detail of the datatype does this cause further downstream effect?

Hey,
thanks for the answer. I did not consider that it's possible to have a node with the same property but different types. Is that a typical use case?

I don't think there are downstream effects. Only it's inconvenient not being sure as to what a "read"-cypher has to look like. Also it could prevent further errors by developers writing cyphers expecting a specific type and then only getting a subset of nodes back because the datatype was different (e.g. 1 and "1").

It strikes me as a rather odd design choice reminding me of early PHP or JavaScript, just being able to put anything into a property. Maybe it's worth the discussion that a property with the same name on the same (labeled) node needs to have the same type as well? Maybe it doesn't matter?

In case you're using docker, you need to re-run the container with these options
docker run
--name testneo4j
-p7474:7474 -p7687:7687
-d
-v $HOME/neo4j/data:/data
-v $HOME/neo4j/logs:/logs
-v $HOME/neo4j/import:/var/lib/neo4j/import
-v $HOME/neo4j/plugins:/plugins
-e NEO4J_apoc_export_file_enabled=true
-e NEO4J_apoc_import_file_enabled=true
-e NEO4J_apoc_import_file_use__neo4j__config=true
-e NEO4JLABS_PLUGINS=["apoc"]
--env NEO4J_AUTH=neo4j/test
neo4j:latest

Then use something like:
match (n:Person) return ID(n),apoc.meta.type(ID(n));

'n.id' didn't work for me.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.