1

Consider I have some users U1, U2, U3 each with property 'age' such that;

U1.age = 10
U2.age = 30
U3.age = 70

I also have some lists which are dynamic collections of users based on some criteria, say L1, L2, L3, such that;

L1: where age < 60
L2: where age < 30
L3: where age > 20

Since the lists are dynamic, the relationship between lists and users is established only through the user properties and list criteria. There is no hard mapping to indicate which users belong to which list. When the age of any user changes or when the criteria of any list changes, the users associated with a list may also change.

In this scenario, at any point of time it is very easy to get the users associated with a list by querying users matching the list criteria.

But to get the lists associated with a user, is an expensive operation which involves first determining users associated with each list and then picking those lists where the result has the user in question.

Could this be a candidate for using Graph Database? And why? (I'm considering Neo4j) If yes, how to model the nodes and the relationships so that I can easily get the lists given a user.

1 Answer 1

1

Since 2.3 Neo4j does allow index range queries. Assume you have an index:

CREATE INDEX on :User(age)

Then this query gives you the list of people younger 60 years and is performed via the index

MATCH (u:User) WHERE u.age < 60 RETURN u

However I would not store the age, instead I'd store the date of birth as a long property. Otherwise you have can the age over and over again.

Update based on comment below

Assume you have a node for each list:

CREATE (:List{name:'l1', min:20, max:999})
CREATE (:List{name:'l2', min:0, max:30})
CREATE (:List{name:'l3', min:0, max:60})

Let's find all the lists a user U1 belongs to:

MATCH (me:User{name:'U1'})
WITH me.age as age
MATCH (l:List) WHERE age >= l.min AND age <= l.max // find lists
WITH l
MATCH (u:User) WHERE u.age >= l.min AND age <= l.max
RETURN l.name, collect(u)

Update 2

A complete different idea would be to use a timetree. Both, all users and your list definitions are connected to the timetree

Sign up to request clarification or add additional context in comments.

2 Comments

So this gives me all users for list L1. But what I need is, given user U1, can I find all the lists that the user belongs to?
I can do this with any RDBMS or flat database as well. Why do you think I should specifically opt for a Graph database to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.