如何使用cypher查询中的nodejs获取对象?

时间:2013-08-17 10:47:17

标签: node.js neo4j cypher

我有以下查询,它给了我想要的东西 - :

'START user=node({userId}), other=node({otherId})',
      'MATCH (user) -[rels?]-> (other)',
      'RETURN rels'

但是我无法访问它发送的对象。我需要关注高亮度的对象,我不知道这个对象。

在下面的控制台中检查对象 - :

[{"rels":{"db":{"url":"http://localhost:7474","_request":{},"_root":..........{},"start":"http://localhost:7474/db/data/node/222","property":"http://localhost:7474/db/data/relationship/245/properties/{key}","self":"http://localhost:7474/db/data/relationship/245","properties":"http://localhost:7474/db/data/relationship/245/properties","type":"knows","end":"http://localhost:7474/db/data/node/196","data":{"created_at":1372829579654}},"_start":{"db":{"url":"http://localhost:7474","_request":{},"_root":...

完整计划:

User.checkRelationship = function (user, fid, callback) {

  var uids = [user.uid, fid];
  async.map(uids, User.by_uid, function (err, usernodes) {
    if (!err && usernodes && usernodes.length) {
    User.relsCheck(usernodes, function (err, rels) {
        if (!err && rels) {
          callback(null, rels);  // inpecting rels gave the above object but I want to return rels.type , but is not giving i want
        } else {
          callback(err || new Error('relationships does\'nt exists'));
        }
      });
    } else {
      callback(err || new Error('Unable to fetch user nodes: ' + uids.join(',')));
    }
  });
};


User.relsCheck = function (nodes, callback) {
  if (nodes.length !== 2) {
    return callback(new Error('Invalid/insufficient arguments'));
  }
  var query = [
      'START user=node({userId}), other=node({otherId})',
      'MATCH (user) -[rels?]-> (other)',
      'RETURN rels'
  ].join('\n');

  var params = {
    userId: nodes[0].node().id,
    otherId: nodes[1].node().id,
  };

   db.query(query, params, callback);
};

1 个答案:

答案 0 :(得分:-1)

如果你想访问原始结果,可能只是原始$ .post并读取结果?