Question

I have User type in neo4j database with a 'registered' property that stores the timestamp (Long) when user joined the site. I want to find how many users have registered before a given date. I defined a query method on the Spring-data Graph repository interface:

@Query("MATCH user=node:User WHERE user.registered < {0} RETURN count(*)")
def countUsersBefore(registered: java.lang.Long): java.lang.Long

I see in the Neo4j manual a lot of queries that just start with MATCH, but Spring-data doesn't seem to like it and requires a START. In my case I don't have an obvious node from where I can start, since my query is not following any relationships, it's just a plain count-where combination.

How can I fix this query? Do I need an index on the 'registered' property?

Was it helpful?

Solution

If you want to use this syntax you have to use Spring Data Neo4j 3.0-M01 which works with Neo4j 2.0.0-M06.

You also need that to be able to use labels.

But better wait for the next milestone version of SDN 3.0 which will work with Neo4j 2.0.0 final.

Update:

If you use the SDN types index:

START user=node:__types__(className="org.example.User") 
WHERE user.registered < {0} 
RETURN count(*) 

or in a repository this derived method should work:

public interface UserRepository extends GraphRepository<User> {
  int countByRegisteredLessThan(int value);
}

OTHER TIPS

Instead of MATCH user=node:User..., you want MATCH (user:User)...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top