1

here is my scenario. I have a pre-defined data type structure for books. Just take it as an example for the sake of simplicity. The structure looks like the image below. It's a Labeled Property Graph and the information is self-explained. This data type structure is fixed, I cannot change it. I just use it.

DTR Example

When there is 1 book, let's call it Harry Potter, in the system, it might look like below:

DTR 1 book

So, the book has its own property (ID, Name,...) and also contains a field type MandatoryData. By looking at this graph, we can know all information about the book.

The problem happens when I have 2 books in the system, which looks like this:

DTR 2 Books

In this case, there is another book called Graph DB, with those information as highlighted.

The problem of this design is: we don't know which information belong to which book. For example, we cannot distinguish the publishedYear anymore.

My question is: how to solve or avoid this problem? Should I create 1 MandatoryData for each book? Could you propose me any design?

I'm using Neo4j and Cypher. Thank you for your help!

Triet Doan
  • 11,455
  • 8
  • 36
  • 69
  • Do you have any flexibility to deviate from this model? It doesn't make sense to have the value as a separate node from the key or context that gives the value meaning. Graphs are all about connections between nodes, especially to data that is common between them (:Author, :Publisher, maybe even :PublishedYear are some good potential common nodes connected to by many books). Other common data probably isn't best modeled that way (such as author name or book title), and should best be handled by index lookup and filtering. – InverseFalcon Nov 22 '17 at 18:00
  • Thanks for your comment. Yes, I can deviate from this model. From your idea, I think it's better to eliminate `Value` node and put their properties inside the node pointing to it. – Triet Doan Nov 22 '17 at 19:15

1 Answers1

0

UPDATE

From the comments (by @AnhTriet):

Thanks for your suggestion. But I want to have some sort of connection between those books. If we create new MandatoryData, those books will be completely separated. (...) I meant, 2 books should point to some same nodes if they have the same author or published year, right?

After some clarification in the comments, I suggest the creation of a MandatoryData node for each property in the database. Then you will connect a given book to various MandatoryData nodes, depending on the number of properties of the book.

This way two books with the same author will be connected to the same MandatoryData node.


Since you cannot change the data model, I strongly recommend you to create a new MandatoryData node for each new book added to the system.

This way you will be able to get informations about the an specific book with queries like:

// Get the author's name of the book with ID = 1
MATCH (:Book {ID : 1})-->(:MandatoryData)-->(:Author)-->(:Name)-->(v:Value)
RETURN v.value

The model proposed in your question is not viable since has no way to identify the owner of an specific property, as indicated by you.

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
  • Thanks for your suggestion. But I want to have some sort of connection between those books. If we create new `MandatoryData`, those books will be completely separated. – Triet Doan Nov 22 '17 at 15:49
  • @AnhTriet And you cannot add relationships between books? Something like `(:Book)-[CONNECTED_TO]->(:Book)` – Bruno Peres Nov 22 '17 at 15:50
  • I can, but it doesn't make sense. I meant, 2 books should point to some same nodes if they have the same author or published year, right? – Triet Doan Nov 22 '17 at 15:53
  • @AnhTriet Yes, I understood now. This data model is very bad for this use case, since you cannot do connections directly to the `:Author` node from a given book. Right? – Bruno Peres Nov 22 '17 at 15:57
  • @AnhTriet A workaround is adding a `MandatoryData` node for each property in the database. Then you will connect a given book to various `MandatoryData` nodes, depending on the number of properties of the book. What you think? – Bruno Peres Nov 22 '17 at 16:00
  • @AnhTriet This way two books with the same author will be connected to the same `MandatoryData` node. – Bruno Peres Nov 22 '17 at 16:03