Neo4j with NodeJS

Posted By : Himanshu Goyal | 04-Feb-2016

Intro: Neo4j is graphical data base in which data is represent in form of nodes and we make the relationship between these node and put the data in these relationship 

node-neo4j: node-neo4j is npm in node to connect with neo4j database. These are various steps to connect with neo4js

  • var neo4j = require('node-neo4j');
  • var neo4jDbConnection=new neo4j('http://neo4j:password@localhost:7474'); //now your connection with database created

Methods:These are method to perform various operation in neo4j

  • it will help to create the node:  neo4jDbConnection.insertNode(jsondata,function(err,node){}) 
  • create relationship between two node:   neo4jDbConnection.insertRelationship(parentnodeId, newNodeId, 'Relationship', {data in relationship}, function (err, node) {}
  • read all incoming relationship: neo4jDbConnection.readIncomingRelationshipsOfNode(NodeId, function (err, obj) {}
  • read all outgoing relationship:  neo4jDbConnection.readOutgoingRelationshipsOfNode(NodeId, function (err, obj) {}
  • remove the node :  neo4jDbConnection.deleteNode(nodeid, function (err, node) {}
  • delete the relationship: neo4jDbConnection.deleteRelationship(nodeid,function(err,node){}
  • update the node with label and data: neo4jDbConnection.updateNodesWithLabelsAndProperties('labelname', { _id: nodeid }, data, function (err, node) {}

Cypher Query  : Cypher query language is used in neo4j. node-neo4j  npm provide the neo4jDbConnection.cypherQuery("query which you want to put",function(err,obj){})

these are various query to help opeartion in neo4j with efficient and easy manner.

  • To delete all the nodes in neo4j:  MATCH (n) DETACH DELETE n
  • To create the node in neo4j:  CREATE (n:Person { name : 'himanshu goyal', company : 'oodles technologies',profile:"developer"})
  • To get all the relationship in neo4j : MATCH (n)-[r]->() RETURN type(r), count(*)
  • Search by unique node id in neo4j : MATCH (s) WHERE ID(s) = 65110 RETURN s
  • delete the particular node neo4j : MATCH (n:user) where ID(n)=42 DETACH DELETE n
  •  main query to create multitple relationship in nodes with single query: 
    Match(p:user),(n:user),(c1:user),(c2:user) where ID(p)=38 and ID(n)=2 and ID(c1)=43 and ID(c2)=44 create (p)-[r:Relationship]->(n), (n)-[r1:Relationship]->c1,(n)-[r2:Relationship]->c2 return p
  • provide the count of nodes : MATCH (:Person) RETURN count(*) AS people

Thanks 

For more information email: himanshu.goyal@oodlestechnologies.com

        

                 

Request for Proposal

Name is required

Comment is required

Sending message..