How to handle this question


(Namestudent) #1

There are some confusions in learning neo4j. I hope you can answer them.

If I need to build a call between cell phone numbers, there are many phone numbers. If this cell phone number and another cell phone number call many times, how should I express it? I think there are some drawbacks in both of them. If the number of calls continues to increase in the future, what should we do? If you build this database, what would you do?


(Aldrin) #2

One way to do it would be to have a single relationship between the two phone numbers and store the number of calls as a property on the relation. Having said that, it would be worthwhile to think ahead of the kind of queries you may want to execute in order to model the structure to efficiently serve those queries


(Namestudent) #3

First of all, thank you for your answer. Secondly, there is another question. Do you mean to use the number of calls as an attribute? If you increase the number of calls each time in the future, how should the attribute be modified?


(Michael McKenzie) #4

If you are interested in just knowing how many times one number calls another, you could just set a relationship attribute like number_of_calls as an integer and just add one every time a call is placed.

However, you are more interested in knowing when these calls are place, then you might want to consider having a unique relationship where each call is logged by date/time. You can still sum up the number of calls with a query. Alternatively, you could store each call date/time in one relationship attribute as an array. Each approach has its pros and cons.

What would you say is your goal with the query at this time?


(Namestudent) #5

Thank you for your answer.

I just learned this database for a short time. Now, a project has a large number of mobile phone numbers. There must be a call relationship between mobile phone numbers and mobile phone numbers. But my consideration is, for example, a hundred calls between one mobile phone number and another mobile phone number. How should I build it?

Store this one hundred times as an attribute with its value of 100. In that case, if the two mobile phone numbers continue to communicate in the future, then I need to reset its value every time, and the call needs to be set once.

So is there any more efficient and convenient way?


(Michael McKenzie) #6

If you are just interested in counting the number of times these phone numbers connect then you can set an attribute on the relationship that counts the number of connections. Any new connections between the numbers can just update the relationship attribute.

Do you have any code you have started building that you can share?


(Namestudent) #7

Thank you for your answer.

It's still in the design phase, and there's no code, so I'm sorry I can't show you.

You mean the number of calls as an attribute, when I set the number of two mobile phones as a call relationship, this relationship contains an attribute: the number of calls, when the next two mobile phones to communicate, the relationship is still a call relationship, the relationship will not increase, I need to manually update the number of calls attribute, right?

Another consideration is that the node name should not be set to a number when it is created, so the mobile phone number can only be displayed by setting it to an attribute.

I don't know much about neo4j. If there are any mistakes, please correct them.:smiley:


(Michael McKenzie) #8

Have you looked into the query language cypher much? It might be easier to work with a rough idea based on cypher.

You are correct in that you would have to update an attribute on the relationship if a new call is placed.

Example 1: Each call from Number 1 to Number 2 is a unique relationship

CREATE (phone1:Phone {num: 555-555-5555})
CREATE (phone2:Phone {num: 444-444-4444})
(phone1)-[:CALLS {date: date1}]->(phone2)
(phone1)-[:CALLS {date: date2}]->(phone2)
(phone1)-[:CALLS {date: date3}]->(phone2)

Example 2: One relationship between 2 numbers with number of calls on relationship:

CREATE (phone1:Phone {num: 555-555-5555})
CREATE (phone2:Phone {num: 444-444-4444})
(phone1)-[:CALLS {number_of_call: 6}]->(phone2)

Each example has its pro and cons and ultimately depends on the question(s) you want to ask.


(Namestudent) #9

Thank you very much for your answer.

Your answer is very helpful to me. Thank you again. I hope we can discuss it more in the future.


(Michael McKenzie) #10

Excellent! I am glad it helped. That's what the community is for!