【问题标题】:neo4jrestclient - query get idneo4jrestclient - 查询获取 id
【发布时间】:2014-09-29 11:48:57
【问题描述】:

我正在使用 neo4jrestclient 库。

from neo4jrestclient.client import GraphDatabase
from neo4jrestclient import client
from neo4jrestclient import query
gdb = GraphDatabase("http://localhost:7474/db/data/")
q = """MATCH n RETURN n;"""
result = gdb.query(q=q)
print(result[0])

当我执行查询“MATCH n RETURN n”时,输出为:

[{
'all_relationships': 'http://localhost:7474/db/data/node/1131/relationships/all', 
'all_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/all/{-list|&|types}', 
'self': 'http://localhost:7474/db/data/node/1131', 
'labels': 'http://localhost:7474/db/data/node/1131/labels', 
'properties': 'http://localhost:7474/db/data/node/1131/properties', 
'create_relationship': 'http://localhost:7474/db/data/node/1131/relationships',
'outgoing_relationships': 'http://localhost:7474/db/data/node/1131/relationships/out', 
'data': {
  'title': 'title', 
  'name': 'Poludnie'
}, 
'incoming_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/in/{-list|&|types}', 
'property': 'http://localhost:7474/db/data/node/1131/properties/{key}', 
'paged_traverse': 'http://localhost:7474/db/data/node/1131/paged/traverse/{returnType}{?pageSize,leaseTime}', 
'incoming_relationships': 'http://localhost:7474/db/data/node/1131/relationships/in', 
'outgoing_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/out/{-list|&|types}', 
'traverse': 'http://localhost:7474/db/data/node/1131/traverse/{returnType}'}]

我看到节点的 id = 1131。问题是:我可以在没有这些链接的情况下以原始形式获得这个 id 吗?我希望只有 id 和“数据”字段的值。

【问题讨论】:

    标签: neo4j neo4jrestclient


    【解决方案1】:

    在 Cypher 中,可以这样表示:

    MATCH (n) RETURN {id: ID(n), name: n.name, title: n.title} as city
    

    在响应中,data 哈希将包含一个数组,每个元素的 row 键将包含可使用其给定键访问的数据。

    【讨论】:

      【解决方案2】:

      要获取“仅 id 和数据,请将查询更改为:

      MATCH (n) RETURN id(n), n.data
      

      看看这是否令人满意。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-01
        • 2018-07-29
        • 1970-01-01
        • 2021-12-16
        相关资源
        最近更新 更多