neo4j:CYPHER查询节点的所有属性 [英] neo4j: CYPHER query all properties of a node

查看:1477
本文介绍了neo4j:CYPHER查询节点的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为将来的项目评估Neo4J。目前,仅在尝试学习Cypher及其功能。但是到目前为止,我认为应该非常简单的一件事。我希望能够看到任何给定节点的所有属性及其值。在SQL中是这样的:

We are evaluating Neo4J for future projects.  Currently just experimenting with learning Cypher and its capabilities.  But one thing that I think should be very straightforward has so far eluded me.  I want to be able to see all properties and their values for any given Node.  In SQL that would be something like:

select * from TableX where ID = 12345;

我浏览了最新的Neo4J文档和大量Google搜索,但到目前为止我还是空着。我确实找到了 keys()函数,该函数将在字符串列表中返回属性名称,但这充其量只是有用的。我想要的是一个查询,该查询将返回prop名称和相应的值,例如:

I have looked through the latest Neo4J docs and numerous Google searches but so far I am coming up empty.  I did find the keys() function that will return the property names in a string list, but that is marginally useful at best.  What I want is a query that will return prop names and the corresponding values like:

name     :  "Lebron"
city     :  "Cleveland"
college  :  "St. Vincent–St. Mary High School"


推荐答案

您可能想重新阅读Neo4j文档。

You may want to reread the Neo4j docs.

返回节点本身将包括属性映射节点,通常这是获取节点所有属性(键和值)的方式。

Returning the node itself will include the properties map for the node, which is typically the way you will get all properties (keys and values) for the node.

MATCH (n)
WHERE id(n) = 12345
RETURN n

如果明确地只需要属性,但没有与节点本身相关的元数据,则返回 properties(n)(假设 n 为一个节点变量)将返回该节点的属性。

If you explicitly just want the properties but without the metadata related to the node itself, returning properties(n) (assuming n is a node variable) will return the node's properties.

MATCH (n)
WHERE id(n) = 12345
RETURN properties(n) as props

w列(变量)有效,它们始终是显式的,因此您没有办法动态获取与节点属性相对应的列。相反,您将需要使用上面的方法,其中变量对应于一个节点(您可以在其中通过结构访问属性图)或属性图。

With regard to how columns (variables) work, these are always explicit, so you don't have a way to dynamically get the columns corresponding to the properties of a node. You will instead need to use the approaches above, where the variable corresponds to either a node (where you can get at the properties map through the structure) or a properties map.

这种方法与SQL中的 select * 之间的主要区别在于Neo4j没有表架构,因此您可以在相同类型的节点上使用所需的任何属性,以及那些相同类型的节点之间可能会有所不同,因此没有要引用的通用结构可以提供给定标签的节点的属性(您需要扫描该标签的所有节点并累积不同的属性才能这样做)。

The main difference between this approach and select * in SQL is that Neo4j has no table schema, so you can use whatever properties you want on nodes of the same type, and those can differ between nodes of the same type, so there is no common structure to reference which will provide the properties for a node of a given label (you would need to scan all nodes of that label and accumulate the distinct properties to do so).

这篇关于neo4j:CYPHER查询节点的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆