Adding comments to Neo4j

As discussed earlier, comments can be used by users to ask more questions or clarify something to other users. Since chronology is important, we will create a chain for the comments. The assumption here is that for a new question or clarification, a new comment chain will be started with the first comment in the chain being in response to the review being commented on.

Before we add comments, we should set up a constraint on comments to ensure that we don't create comments with the same ID, as shown in the following query:

neo4j-sh (?)$ CREATE CONSTRAINT ON (comment:Comment) ASSERT comment._id IS UNIQUE;

The output of the preceding query is as follows:

+-------------------+ | No data returned. | +-------------------+ Constraints ...

Get Neo4j Graph Data Modeling now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.