2013-08-17 50 views
1

我有以下查詢這是給我我想要的東西 - :如何從cypher查詢中使用nodejs獲取對象?

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

但我無法訪問它send.I需要以下高輕量化的對象,我不知道要訪問的對象。

對象在以下控制檯檢查 - :

[{"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

如果您要訪問的原始結果,也許只是到原始$。員額和讀取結果?

相關問題