2

I am developing social networking website now a days. for that I am using MySql as my primary database and neo4j as in-memory database. I am using node.js and (for neo4j) too.

Now I have a some doubt regarding data modelling for neo4j. I want to give some feathers to my users like friends suggession, mutual contacts and searching. This all stuff I have implimented with My-Sql. But due to some performance issue, I would like to store friends and it's relations related data in to neo4j. For that I have stored my User's nessessory information into neo4j as node. I have already primary key in mysql database. and here neo4j also have it's own id system. So how can I bind this both ids togather. I have read this blog (https://github.com/aseemk/node-neo4j-template/blob/master/models/user.js) and trying to do as he mentioned in his blog.

Second thing is How to give suggession list to my user from neo4j database. Right now I am giving UserName with his/her Image and mutual friends count (with login user) and city in suggession list. I don't understand How I do this with neo4j within node.js?

I have read many blogs and watched many videos over internet. but still I am not getting any idea to do this work.

Can some one help me or can suggest me to where can I get proper information regarding this? I am very much confused and frustrated, and not getting any clue to achive my task.

Sorry for my bed English.

Manish Sapkal
  • 5,591
  • 8
  • 45
  • 74

1 Answers1

4

For your first question, take a look at http://blog.neo4j.org/2013/04/data-migration-between-mysql-and-neo4j.html and see if you could apply similar principles.

To send back suggestions based on your Neo4j model, you could consider exposing a REST api for example, which basically operates over your graph database by querying/collecting information and then returning it. Your application then just talks to the API rather than deal with two underlying stores. As you've already figured out, the driver for Node.js is https://github.com/thingdom/node-neo4j and you can use that to talk to Neo4j.

Perhaps you could provide more details on what exactly you're stuck with?

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • +1 for just using API's. It's my strategy with Neo4j, everything goes over the REST API. – OpenCoderX Jun 27 '13 at 15:03
  • Thanks for reply @Luanne. I have first question about relation between both database (eg. mysql and neo4j). As per my understanding, Should I have to store mysql table's id in neo4j node's property? and neo4j node's id in mysql table (eg. In mysql database there is a primary table for user is "UserMaster". In that table I have Primary Key named "UserID" as well as "GraphID", which is refer to neo4j node's id? Is it right way? what happen when in such a case I have to remove all key for neo4j and re-enter same data (In this case id will be changed). – Manish Sapkal Jun 28 '13 at 05:56
  • If MySQL is your primary database, then yes, the primary key in the UserMaster table will have to be stored as a property on your User node in Neo4j to be able to refer to the same entity by key in both databases. You can call this property anything- userId or id. If you call it id then it is very different from Neo4js internal ID so you don't have to worry about that(deleting all nodes and recreating will not cause any issue because you are not using the internal ID). You probably don't have to store the node ID in MySQL because you can still look up nodes in Neo4j by indexing the userID. – Luanne Jun 28 '13 at 09:36
  • thanks again. It is very useful information for me. But now I want to know How to index Neo4j property. I want to search many fields from Neo4j like UserId, UserName, EMailID, Mobile No. etc. And one more thing, Can I set Neo4j's internal id as my MySql's userId? – Manish Sapkal Jul 01 '13 at 06:37
  • No, you cannot set Neo4j's internal ID. However you can create a property called "userId" and set it to the MySQL userId and then index this property. Indexing is described here: http://docs.neo4j.org/chunked/stable/indexing.html – Luanne Jul 01 '13 at 08:48
  • Thanks @Luanne. I had read this blog : https://github.com/aseemk/node-neo4j-template/blob/master/models/user.js. But I can not understand how to retrieve node which I require. means I have login UserID from mysql, and I want node from neo4j (which is already stored previously). so, I have to get it from neo4j. but how that I doesn't understand? can you give some hint? or you can suggest me, from where can I link? If so, It is very much helpful for me. thanks. – Manish Sapkal Jul 02 '13 at 11:35
  • Did you read http://docs.neo4j.org/chunked/stable/indexing.html as well? You can create your node, add it to the index as explained here http://docs.neo4j.org/chunked/stable/indexing-add.html and then find that node by accessing it via the index as described here: http://docs.neo4j.org/chunked/stable/indexing-search.html. You can also use Cypher to find the node: http://docs.neo4j.org/chunked/stable/query-start.html#start-node-by-index-lookup – Luanne Jul 02 '13 at 13:19
  • @Luanne, I have read and understand conceptually. But I am using node.js and withing node.js How to do it, that I can't understand. – Manish Sapkal Jul 03 '13 at 06:10
  • Well I don't really know node.js but I see how to index a node in https://github.com/thingdom/node-neo4j/blob/develop/test/crud._coffee Maybe you can go through the tests or read http://coffeedoc.info/github/thingdom/node-neo4j/master/ If you have some example of what exactly you tried and what is failing, would be good to post that as a new question – Luanne Jul 03 '13 at 07:37
  • Hi @Luanne, When I am trying to get node it return result like this. – Manish Sapkal Jul 08 '13 at 10:27