Reference to the above image, nodes on the left are "Label_1", nodes on the right are "Label_2". On Label_2, the node which has the properth "F"(the middle node on right) has 2 relationships connected to it. We can return that node by either querying the nodes that has the property "B" or propery "C".
Is it possible to return that node with property "F" only if both the nodes are connected to it(the nodes that has the property "B" and propery "C") are queried?
Thanks for your reply. We can also return the nodeF by simply querying either of the node B or C. But I wanted the nodeF to be returned "only" if both nodeB and C are queried.
Hey again.
I am not sure I understand your use-case. Could you elaborate in more detail?
Also what do these Relationships represent?
The query I posted above will return node F only when both "A" and "C" connect to it. The query matches the exact pattern that both "A" and "C" connect to "F".
When querying patterns, you want nodes only to be returned, if all of their ingoing relationships (relationships to the node) have been queried? The number of ingoing relationships might vary. Only if all of them are part of the pattern, your query will return the node.
I made a generalized version of the query above.
If you have control over the queries that go to the database, you can wrap your query in the following way.
This feels very hacky and I don't like it.
match(targetnode:Label_2{name:"F"})<-[r]-()
with count(r) as countrelationships,targetnode
match(sourcenode:Label_1)-[q]->(targetnode)
// Put all the connected nodes you want to query here
where sourcenode.name="B" or sourcenode.name="C"
//
with count(*) as querycount,countrelationships,targetnode
where querycount=countrelationships
return targetnode;
No Rows will be returned if targetnode has more ingoing relationships than connected nodes queried.
Still, if users have DB-accounts, they can use queries as they wish. You'll have to wrap their queries like this in another layer of your software, in your application.
I think what you want to do is not supported by Neo4J.