MERGE cypher not returning a value?

36 views
Skip to first unread message

Kevin Burton

unread,
Jan 28, 2016, 4:02:34 PM1/28/16
to Node-Neo4j
Enter code here...

I have a cypher query that looks like:

return new Promise(function (resolve, reject) {
        db.cypher({
query: 'MATCH (fi:FormDefinitionImageIndex {id: ' + row.formDefinitionImageIndexFieldID + '}),' +
'(d:FormDefinitionImage {id: ' + row.formDefinitionImageID + '})' +
' MERGE (fi)-[:IMAGEINDEX]->(d) '
},
function (err, result) {
if (err) {
return reject(err);
} else {
return resolve(result);
}
});
}).then(function (results) {
if(results.length == 0) {
console.log('No FormDefinitionImageIndexField relationships for (' + row.formDefinitionImageIndexFieldID + ' <-> ' + row.formDefinitionImageID + ') index field key ' + row.indexFieldKey);
} else {
console.log('FormDefinitionImageIndexField relationship ' + results.length);
}
return results;
});

As can be seen from the code I would expect an array of results when the promise is "resolved". But instead I am getting a single zero lengthed array. The cypher query forms the relationship but it is odd that the return value is empty. Ideas?

Thank you.

Kevin

Michael Hunger

unread,
Jan 28, 2016, 4:19:25 PM1/28/16
to Kevin Burton, Node-Neo4j
1. you should use parameters, not string concatenation
2. if either of the matches doesn't match anything the merge will never be called, make sure they actually both produce a hit

Kevin Burton

unread,
Jan 28, 2016, 4:54:36 PM1/28/16
to Node-Neo4j, ronald.ke...@gmail.com
Thank you for your recommendation to use parameters. The query is succeeding because I can go on the browser interface and see the relationship created. It doesn't seem to pass a pass/fail indication.

Michael Hunger

unread,
Jan 28, 2016, 5:25:26 PM1/28/16
to Kevin Burton, Node-Neo4j
Oh sorry and you don't return anything, so it will return nothing as you requested :).

Kevin Burton

unread,
Jan 29, 2016, 8:49:46 AM1/29/16
to Node-Neo4j, ronald.ke...@gmail.com
I am going to take your suggestion. But I am having a problem with the understanding.of how properties are used. Say I have the following query:

db.cypher({ query: 'MATCH (r:AutoFillRule {id: ' + row.autoFillRuleID + '}), ' +
'(g:AutoFillRuleGroup {id: ' + row.autoFillRuleGroupID + '})' +
' MERGE (r)-[:AUTOFILL]->(g)' +
' RETURN COUNT(*)'


Notice that the property key is the same for both places that I would like to use properties. So I cannot just do something like: 'props['id'] = row.autoFillRuleGroupID' How should I use properties in this case? Thanks again.


On Thursday, January 28, 2016 at 3:19:25 PM UTC-6, Michael Hunger wrote:

Michael Hunger

unread,
Jan 29, 2016, 9:07:20 AM1/29/16
to Kevin Burton, Node-Neo4j
I said parameters not properties :)

db.cypher({ query: 'MATCH (r:AutoFillRule {id: {autoFillRuleId}}), ' +
'(g:AutoFillRuleGroup {id: {autoFillRuleGroupID}})' +

' MERGE (r)-[:AUTOFILL]->(g)' +
                   ' RETURN COUNT(*)', params: {autoFillRuleId: row.autoFillRuleID, autoFillRuleGroupID, row.autoFillRuleGroupID  })
Reply all
Reply to author
Forward
0 new messages