Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-08-2020 12:43 AM
Hello,
I am playing around with the plugin system of neo4j.
I just want to call my function with an ID and want the neighbours of this node returned as a String:
public class Neighbours {
@Context
public GraphDatabaseService db;
@UserFunction
public String neighbours(@Name("nodeId") long nodeId) {
Node node = db.findNode(Label.label(""), "id", nodeId);
return StreamSupport.stream(node.getRelationships().spliterator(), false)
.map(neighbourNode -> neighbourNode.getProperty("id").toString())
.collect(Collectors.joining(", "));
}
}
Calling my function causes this error:
Neo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke function `example.neighbours`: Caused by: java.lang.NoSuchMethodError: org.neo4j.graphdb.GraphDatabaseService.findNode(Lorg/neo4j/graphdb/Label;Ljava/lang/String;Ljava/lang/Object;)Lorg/neo4j/graphdb/Node;
I also tried other methods of GraphDatabaseService, no luck.
What is wrong with my function? I am using neo4j-community-4.0.4.
Also I do not have any labels on my nodes. Would my above implementation work to retrive my label-less nodes or do I have to use null
as parameter?
//edit: ok, seems like the procedure-template on github ist for neo4j 3.x and I am using 4.x.
Is there any documentation on how to do this in the newer Neo4j?
06-08-2020 09:39 AM
We need to fix the lack of procedure template!In the meantime, you can find some example in Max De Marzi's blog:
06-12-2020 03:38 AM
I had to update the version numbers in the pom.xml and first begin a transaction.
Now I can call findNode
on the transaction object to retrieve a node.
But I cannot figure out how to find a node which does not have a label present.
Node node = tx.findNode(Label.label(""), "id", nodeId);
This does not return any node. I also tried with *
as label and with null
(which causes a NPE), but nothing works.
06-29-2020 06:56 AM
Node node = tx.findNode(Label.label(""), "id", nodeId);
This method is trying to find using property named "id". This is similar to
MATCH (n) where n.id=nodeId
I don't think that is correct way to retrieve node by it's node id.
Can you try
Node node = tx.getNodeById(nodeId)
This will retrieve the node by it's nodeId.
06-29-2020 03:19 AM
I think you may have to find the node via the tx.getAllNodes()
function and then check the property on each node until you find the one you want.
All the sessions of the conference are now available online