2014-09-29 66 views
0

我正在使用neo4jrestclient庫。neo4jrestclient - 查詢獲取ID

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 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

回答

1

在Cypher支架,其可以表達如下:

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

在響應中,該data散列將包含一個陣列,並且每個元件的row鍵將使用其給定的密鑰包含可訪問這些數據。

1

得到「公正的ID和數據,更改查詢:

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

看看這是否令人滿意。