@KateLatte's suggestion to use Memgraph's degree function is the best answer if you truly want to find all "orphan nodes", since it should be fast.
But I want to also correct your original openCypher
query. Assuming that you are using Memgraph 2.5.2, your query was not actually attempting to find all "orphan nodes". It is just looking for NodeA
nodes that have no outgoing relationship to a NodeB
node.
To find all orphan nodes in openCypher, you should have to used this query:
MATCH (n)
WHERE NOT (n)--()
RETURN n;