我有以下查询,这给了我想要的东西-:
'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);
};