Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-05-2020 03:21 AM
HI
when i execute the folllowing cmd
`MATCH (n:process) RETURN DISTINCT keys(n) AS ProcessKey;`
I get 2 rows back, keys ar identical but sorting is different
["timestamp_unix_changed", "timestamp_unix_lastread", "name", "timestamp_unix_creation", "guid"]
["timestamp_unix_creation", "timestamp_unix_changed", "name", "timestamp_unix_lastread", "guid"]
Thanks rob
You can reproduce the error with
MATCH (n:test) Delete n;
CREATE (n:test {name: 'I', prob_AA: 'terst'});
CREATE (n:test {prob_AA: '12QW', name: 'II'});
CREATE (n:test {name: 'III'});
MATCH (n:test {name: 'III'}) SET n.prob_AA = "SDFGHGFDSDFGHJHGFDSASDFGHJK";
MATCH (n:test) RETURN DISTINCT keys(n) AS Keys;
["prob_AA", "name"]
["name", "prob_AA"]
Solved! Go to Solution.
12-05-2020 08:49 AM
Oddly enough, I recently discovered a similar problem that's not correctly answered in this otherwise very interesting and useful video:
https://www.youtube.com/watch?v=BN5T8IimB78 at 31:40
Here's my solution to fix it
MATCH(p1:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(p2:Person)
WHERE m.title = 'Top Gun'
WITH p1, p2 ORDER BY [p1.name]
RETURN COLLECT(distinct (apoc.coll.sort([p1.name, p2.name])))
12-05-2020 05:21 AM
Hello @rob2
I'm not sure what you were trying to achieve, but this is a query (you will need APOC) that will collect all keys and sort them and it will return a set of keys:
MATCH (n:test) RETURN apoc.coll.sort(apoc.coll.toSet(apoc.coll.flatten(collect(keys(n))))) AS Keys;
Regards,
Cobra
12-05-2020 08:14 AM
HI
i should have told you what I try to archiev. It shell be a consitency check. All nodes withe the same label MUST have the same keys. I try to finde out if this is true.
Unfortunately, your answer is not a solution even if I have modified it a little ... (my fault)
MATCH (n:test) Delete n;
CREATE (n:test {name: 'I', prob_AA: 'terst'});
CREATE (n:test {prob_AA: '12QW', name: 'II'});
CREATE (n:test {name: 'III'});
MATCH (n:test {name: 'III'}) SET n.prob_AA = "SDFGHGFDSDFGHJHGFDSASDFGHJK";
CREATE (n:test {prob_cc: '12QW', name: 'OTHER'});
MATCH (n) RETURN apoc.coll.sort(apoc.coll.toSet(apoc.coll.flatten(collect(keys(n))))) AS Keys, labels(n);
Any idea how I can get the info? Create would be if i get a 0 if it is TRUE and FAlse if the keys are different.
thansk rob
12-15-2020 06:56 PM
The properties of a node, by design, do not follow any order. That's why
CREATE (n:test {name: 'I', prob_AA: 'terst'});
CREATE (n:test {prob_AA: '12QW', name: 'II'});
Here you used 'CREATE' and this creates two nodes. Same query if run with MERGE:
MERGE (n:test {name: 'I', prob_AA: 'terst'});
MERGE (n:test {prob_AA: '12QW', name: 'II'});
This will create only one node and displays the order of the properties as in the first created node. MERGE is CREATE IF NOT EXISTS.
12-05-2020 08:49 AM
Oddly enough, I recently discovered a similar problem that's not correctly answered in this otherwise very interesting and useful video:
https://www.youtube.com/watch?v=BN5T8IimB78 at 31:40
Here's my solution to fix it
MATCH(p1:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(p2:Person)
WHERE m.title = 'Top Gun'
WITH p1, p2 ORDER BY [p1.name]
RETURN COLLECT(distinct (apoc.coll.sort([p1.name, p2.name])))
All the sessions of the conference are now available online