3

I know that neo4j stores data structured in graphs rather than in tables. In RDBMS we will be having schemas of the tables but in neo4j we will not be having the tables. Only nodes, relations and properties are defined. So is there any concept of metadata in neo4j. Like is there any information stored about nodes, relationships in the database? If yes, how and what it stores in the metadata? Also where can we find the metadata related information in the graph database (location)

Thanks,

Benny
  • 432
  • 1
  • 6
  • 21
shree11
  • 535
  • 4
  • 13
  • 26
  • 1
    Have you read the [manual](http://docs.neo4j.org/chunked/milestone/index.html), particularly [the chapter on schema](http://docs.neo4j.org/chunked/milestone/graphdb-neo4j-schema.html)? How about other introductory materials [1](http://www.neo4j.org/learn),[2](http://neo4j.com/graphacademy/online-course/),[3](http://neo4j.com/guides/graph-concepts/),[4](http://neo4j.com/docs/2.0.2/data-modeling-examples/)? – jjaderberg Jul 24 '14 at 11:13
  • @jjaderberg, I gone through the manual where schema is explained. But there they have explained creating and working with INDEX and CONSTRAINT. So i;m looking or expecting some other answer. Here my schema/metadata refers to something different apart from index and constraints. Like in rdbms somewhere in the database the information of tables are stored as a schema file. Similar way does neo4j database stores any information of nodes and properties in any file in the databases? – shree11 Jul 24 '14 at 11:36

3 Answers3

5

Neo4J doesn't directly store metadata in the way that you're looking for. The NeoProfiler tool was written precisely for this purpose. You can run it on a Neo4J database, and it will pull out as much information on labels, indexes, constraints, properties, nodes, and relationships as it can. The way that this works isn't too far off of the queries that @ulkas suggests in the other answer here, the output is just much better.

More broadly, in an RDBMS the schema information you pull out substantially constrains the database. The schema there is like a set of rules; you can't insert data unless it conforms to that schema. In Neo4J, because it's so flexible, even if there was a schema it would just be documentation of what's there, it would not be a set of constraints on what you can put in. At any time, you can insert new data that has nothing to do with the present schema (except that you can't violate things like uniqueness constraints).

If you want to see an equivalent schema for your database in neo4j, check out neoprofiler linked above. A few people out there have written about "metagraphs" - that is, they talk about representing a neo4j schema as a graph itself, where for example a node refers to a label. Relationships from that "label node" then go out to other kinds of label nodes, specifying what sorts of relationships can exist between nodes. For example, nodes labeled "Employee" may frequently have "works_for" relationships to nodes of label "Company".

FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86
  • @ Frobber, The concept is very well explained and will look into neoProfiler. Thanks a lot – shree11 Jul 25 '14 at 05:09
  • I know that this is an old question, but just to add on the top of the (good) answer above, another route might be to use the recently released [MindmapsDB](https://mindmaps.io/pages/index.html), that is developed exactly with the problem described by the OP in mind. Full disclosure: I work for MindmapsDB, but it's an open source project and I am not trying to sell anything. – MiKo Oct 12 '16 at 15:12
3

no, direct metadata are not present. the maximum you can do is to query all the structure types and have a small inside what kind of graph could be stored in the db.

START r=rel(*)
RETURN type(r), count(*)
START n=node(*)
RETURN labels(n), count(*)

the specific database files are stored in the folder data/graph.db but besides some index and key files they are binary and not easy to read.

ulkas
  • 5,748
  • 5
  • 33
  • 47
  • @ ulkas, Thanks to guide in the cypher side to get the nodes and relationships information. But when i run the above query it's giving me an error. Asking for WITH keyword in between START and RETURN. Even after writing WITH it's giving me an error. – shree11 Jul 25 '14 at 05:24
  • @ ulkas, Thanks to guide in the cypher side to get the nodes and relationships information. When i run the above query seperatatly for nodes and relationships (i.e., 1st 2lines and last 2lines),I'm getting the output. But when i run the above complete query(4lines at a time) it's giving me an error. Asking for WITH keyword in between START and RETURN. Even after writing WITH it's giving me an error.So how can i get the output saying both nodes and relationships information after running a single script. – shree11 Jul 25 '14 at 05:36
  • @shree11 that's because those are 2 separate queries. either run them two times, or try to `union` them – ulkas Jul 25 '14 at 07:27
0

Meanwhile there is the official APOC Library.
This includes functions like apoc.meta.graph, apoc.meta.schema and others.

The link above describes the installation, if you run into sandbox errors, check the answers in this question

til
  • 832
  • 11
  • 27