cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Need help for query

match(n:user{USR_ID:'15200'})--(r)--(m:user) with n,r,m
call apoc.do.when(exists(r.mobile), create(a:ids{id:n.USR_ID})-[:linked]-(m),create(a:ids{id:n.USR_ID})-[:not_linked]-(m), '') yield a return 1

there is syntax error can any one help

11 REPLIES 11

shan
Graph Buddy

Your create command needs to be inside quotations

Also your inner query needs to RETURN something otherwise the call won't YIELD a row

can you give example for the same

MATCH (n:user{USR_ID:'15200'})--(r)--(m:user) 
WITH n,r,m
CALL apoc.do.when(exists(r.mobile), 
 "create(a:ids{id:userId})-[:linked]-(m) RETURN a" ,"create(a:ids{id:userId})-[:not_linked]-(m) RETURN a", {m:m, userId:n.USR_ID}) YIELD value 
RETURN 1

I realized those creates must have been intended to be the if and else part, not both in the if, so I separated them. Also as you're looking to create a new :ids node for a in both cases from n's USR_ID, I made sure we're passing in the variables to the call that need to be used in those queries.

thanks it worked for ..
but i need little help...
can you share me some source from where i can understand the background working of cypher queries

it would be great help for me to understand neo4j more efficiently

Hi, Yeshveer
What was really worked wel for me - simple official manuals!
https://neo4j.com/docs/cypher-manual/current/syntax/
Also I advice you to learn and be aware of handy APOC functionality. 99% of Cypher queries uses APOC:
https://neo4j.com/docs/labs/apoc/current/
Bonus: Having a chance to advertise something, may I advertise you my blog-post of Cypher Tutorial. It have Cypher Quiz so you can try your skills after learning some Cypher basics:


Cheers,
Vlad

in this case multiple ids are being made with same value..

but i need only two ids node
one have all linked node connected and other have all not_linked note connected ..

i tried merge also but not getting what i want ..

Your query has the :ids node created with a specific id, the the id the :user from your first match. If you only need two :ids nodes, then you can't use a property that depends on the user's id (unless there are only two :user nodes, thus only two ids to use).

You may need to explain more about what you're really trying to do here, I don't think we have a clear context.

here situation is ...
suppose a user is coonected to a mobile node with relation [HAVE_MOBILE] and similarly to other nodes
and other user is also connected to these node mobile and other with same relation .
now i want user which are connect through mobile node to each other should form one group which i named as ids and remaining connect to other group .

!

That makes sense when there's one obvious central node. But what about patterns where there isn't one obvious central node? Let's say you had multiple graphs like these that were connected to each other such that there wasn't some obvious central node. Which user node would you use in this case?

Also, from the point of view of n and m, it looks like you would create an ids node for each (if you weren't specifying the USR_ID for n). What means do you want to use to choose between the connected nodes, which one should be used for the id?

ok let the id of central node be any thing. id does not matter i need to make these groups
let id be some random number or 1
here central node is not the concern. we can change that, but grouping is important