skip to Main Content

I am currently working with Neo4j and using the Popoto.js library. However, I have come across an issue regarding the customization of node labels in the generated queries.

To provide some context, when Popoto.js generates a query for a node with a specific label, it includes the label as part of the node identifier, which can lead to queries that are not accepted by the Neo4j database. For example, the generated query looks like this:

MATCH (node::test:`Node::test`) RETURN node::test

As mentioned, this query format is not compatible with the Neo4j database. I am wondering if there is a solution or workaround to customize the query and achieve the desired result. Specifically, I would like to generate a query in the following format:

MATCH (n:`Node::test`) RETURN n

PS: i can’t remove the ‘::’ from nodes
This modified query format would allow me to work with the Neo4j database seamlessly.

I would greatly appreciate any guidance or insights you can provide regarding this issue. Thank you in advance for your assistance.

I tried to update popoto.start function to generate a custom node label, but am still looking for a solution.

2

Answers


  1. For the query to be "correct" you need to escape variables and labels that contain special characters:

    MATCH (`node::test`:`Node::test`) RETURN `node::test`
    

    Documentation: https://neo4j.com/developer/cypher/style-guide/#_backticks

    I suggest you create a new issue in the popoto repo since this is most likely an easy fix there.

    Login or Signup to reply.
  2. Here is a link to the popoto function that generates a node identifier based on the node label, which I copy here:

    /**
     * Create a normalized identifier from a node label.
     * Multiple calls with the same node label will generate different unique identifier.
     *
     * @param nodeLabel
     * @returns {string}
     */
    node.generateInternalLabel = function (nodeLabel) {
        var label = nodeLabel ? nodeLabel.toLowerCase().replace(/ /g, '') : "n";
    
        if (label in node.internalLabels) {
            node.internalLabels[label] = node.internalLabels[label] + 1;
        } else {
            node.internalLabels[label] = 0;
            return label;
        }
    
        return label + node.internalLabels[label];
    };
    

    You can change the function to not use the node label (in your own fork of the linked repo).

    For example, to generate the identifiers n, n1, n2, etc., you can replace this line:

    var label = nodeLabel ? nodeLabel.toLowerCase().replace(/ /g, '') : "n";
    

    with this:

    var label = "n";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search