1

neo4jグラフデータベースに接続するためにnode-neo4jを使用しています。すべてのノード (ユーザーなど) を取得しようとするたびに、json の結果の戻り値に必要のない情報が多すぎることに気付きました。

すべてのユーザー ノードを返すコードは次のとおりです。

User.getAll = function (callback) {
    var query = [
       'MATCH (user:User)',
       'RETURN user',
    ].join('\n');

    db.query(query, null, function (err, results) {
        if (err) return callback(err);
        var users = results.map(function (result) {
           return new User(result['user']);
        });
        callback(null, users);
    });
 };

そして、これらのjson応答が得られました。

[
{
    "_node": {
        "_nodeNeo4j": {
            "version": "1.1.0",
            "constructor": "Node"
        },
        "_data": {
            "extensions": {},
            "outgoing_relationships": "http://localhost:7474/db/data/node/13/relationships/out",
            "labels": "http://localhost:7474/db/data/node/13/labels",
            "all_typed_relationships": "http://localhost:7474/db/data/node/13/relationships/all/{-list|&|types}",
            "traverse": "http://localhost:7474/db/data/node/13/traverse/{returnType}",
            "self": "http://localhost:7474/db/data/node/13",
            "property": "http://localhost:7474/db/data/node/13/properties/{key}",
            "properties": "http://localhost:7474/db/data/node/13/properties",
            "outgoing_typed_relationships": "http://localhost:7474/db/data/node/13/relationships/out/{-list|&|types}",
            "incoming_relationships": "http://localhost:7474/db/data/node/13/relationships/in",
            "create_relationship": "http://localhost:7474/db/data/node/13/relationships",
            "paged_traverse": "http://localhost:7474/db/data/node/13/paged/traverse/{returnType}{?pageSize,leaseTime}",
            "all_relationships": "http://localhost:7474/db/data/node/13/relationships/all",
            "incoming_typed_relationships": "http://localhost:7474/db/data/node/13/relationships/in/{-list|&|types}",
            "data": {
                "uid": "53c7a820-f0b4-11e3-af63-28373723792e",
                "name": "user1"
            }
        }
    }
},

サイファーからの結果の「データ」部分を返すだけの方法はありますか? または、結果をクライアントに返す前に、node.js サーバーの不要な部分を削除する必要がありますか?

ありがとう!

4

3 に答える 3

1

ノードの代わりにフィールドを返すようにクエリを更新できます...

...
RETURN user.uid, user.name

それは結果セットをフィールドのデータ「グリッド」に近づけますが、それがあなたが探しているもののように聞こえます

于 2014-06-10T17:15:46.670 に答える