I am trying to create new nodes and relationships using Neo4j using Spring Data Neo4j. My use case is to add a friend relationship between 2 user nodes. So this boils down to :
User user1 = userRepo.findByPropertyValue("userId1", userId1);
User user2 = userRepo.findByPropertyValue("userId2", userId2);
if(user1 == null){
createUserObject(userId1);
}
if(user2 == null){
createUserObject(userId2);
}
user1.isFriend(user2);
userRepo.save();
So this includes 2 calls to the DB (findByPropertyValue). Is this correct or is there another way to do this ? Maybe batch the whole thing up into one request ?
Thanks..
You can do both with a single cypher query:
The user-id's are passed in as params in a map.
You can also use an annotated repository method for that.