使用 Cypher,如何 return 一个只有其属性子集的节点
Using Cypher, how to return a node with only a subset of its properties
假设我在 Neo4j 中创建了一个节点:
CREATE (:Thing {a:'foo', b:'bar'})
我可以编写一个查询来获取该节点及其所有属性
MATCH (n:Thing {a:'foo'}) RETURN n
哪个return
{
"a": "foo",
"b": "bar"
}
但是是否可以匹配一个节点并仅检索其属性的一个子集,例如,Neo4j 将 return 一个 node with only
{
"b": "bar"
}
(不只是寻找 属性,就像您通过 RETURN n.b
得到的一样)
是的,您可以在 Cypher 中使用地图投影,例如:
MATCH (n:Thing {a:'foo'}) RETURN n{.a}
将 return :
{a:"foo"}
更多信息在 documentation
假设我在 Neo4j 中创建了一个节点:
CREATE (:Thing {a:'foo', b:'bar'})
我可以编写一个查询来获取该节点及其所有属性
MATCH (n:Thing {a:'foo'}) RETURN n
哪个return
{
"a": "foo",
"b": "bar"
}
但是是否可以匹配一个节点并仅检索其属性的一个子集,例如,Neo4j 将 return 一个 node with only
{
"b": "bar"
}
(不只是寻找 属性,就像您通过 RETURN n.b
得到的一样)
是的,您可以在 Cypher 中使用地图投影,例如:
MATCH (n:Thing {a:'foo'}) RETURN n{.a}
将 return :
{a:"foo"}
更多信息在 documentation