2

I am pretty new to sailsJS and Neo4J, my roadblock is to create relation between two nodes with reference ID.

My Code Sample :

    params.id = 'b8995544-02fc-4148-807f-d9c9f0ebd60f';
    var q = [
        'MATCH (w:word{id:'+ JSON.stringify(params.id)+ '}),(a:audiofiles{wordId:'+JSON.stringify(params.id)+'}) CREATE (w)-[r:HASMANY]->(a) RETURN r' 
    ];
    connections[connection].connection.query(q.join(' '), {}).then(function (result) {
        console.log(result);
        cb(null, result);
        }, function (err) {
        cb(err, null);
        console.log(err);
    });

My Output is something:

     [ 'MATCH (w:word{id:"faedcf89-b323-48f4-9c29-f4396822f83c"}),(a:audiofiles{wordId:"faedcf89-b323-48f4-9c29-f4396822f83c"}) 
    CREATE (w)-[r:HASMANY]->(a) RETURN r' ]

    { columns: [ 'r' ],
 data: [],
   status:
      { httpCode: '200',
        statusCode: '200',
        httpMessage: 'OK',
        httpDescription: 'Request succeeded without error' } }

Even then it is not creating relation at Neo4J any issue, I am unable to debug at this framework. Can any one help me what is the root cause which doesnt creating relation between these.

Ayyappa A
  • 657
  • 3
  • 8
  • 24

1 Answers1

1

Not sure where you see an issue when you get an http-200 back, which is good.

If you mean that data is empty -> it would contain the newly created relationship's properties, and as you have none, it will not contain data. You can also return id(r) or type(r)

In this case it might just be that you have a typo somewhere either in your id. Or property-name or whatever. Try to run the query manually if your MATCH actually finds the word and the audiofiles. (Btw. labels are usually capitalized, not lowercase)

You should use parameters!

params.id = 'b8995544-02fc-4148-807f-d9c9f0ebd60f';
var q = 
    'MATCH (w:word{id:{id}}), (a:audiofiles{wordId:{id}}) CREATE (w)-[r:HASMANY]->(a) RETURN r';
connections[connection].connection.query(q, params).then(function (result) {
    console.log(result);
    cb(null, result);
    }, function (err) {
    cb(err, null);
    console.log(err);
});
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • Thanks for your quick response, I have gone through written code, but i didnt found any Typo error in the above code. not able to debug the issue even. – Ayyappa A Oct 13 '15 at 06:33