简体   繁体   English

Neo4j 如何使用 Java 驱动程序通过密码查询检索节点列表

[英]Neo4j how to retrieve List of Nodes by cypher query using Java driver

    StatementResult result = graphBasicService.readStatement(query);
    while (result.hasNext())
    {
        Record record = result.next();
        // Values can be extracted from a record by index or name.
        System.out.println("nodes: "+record.asMap().values());
    }

As In above code example I am trying to retrieve node that has values {mobile, status} .正如在上面的代码示例中,我试图检索具有值 {mobile, status} 的节点。 Though on browser I get List, with above code I just get one value.(One mobile number).虽然在浏览器上我得到了列表,但上面的代码我只得到了一个值。(一个手机号码)。

More on I get results printed as更多关于我得到的结果打印为

mobile: [node<9>]移动:[节点<9>]

What does 9 denotes here? 9在这里代表什么? And how I can retrieve list of nodes to print mobile number.以及如何检索节点列表以打印手机号码。

In case you require query:如果您需要查询:

MATCH (n :User {mobile:"9999999"}) -[r :CONTACT] -> (m :User {withm:"true"}) - [r2:CONTACT] -> (n) return m MATCH (n :User {mobile:"9999999"}) -[r :CONTACT] -> (m :User {withm:"true"}) - [r2:CONTACT] -> (n) return m

Note: graphBasicService is my custom method that executes above query.注意: graphBasicService 是我执行上述查询的自定义方法。

Question Summary: I am trying to retrieve and print List of Nodes, and am unable to do so.问题摘要:我正在尝试检索和打印节点列表,但无法执行此操作。

I don't see any lists here.我在这里没有看到任何列表。 There's no collect() in your query, or any other function or procedure that would produce a list.您的查询中没有collect() ,也没有任何其他会生成列表的函数或过程。 You're just getting a stream of result records.你只是得到一个结果记录流。

You'll get one node per record with this query, so if you want a list, you would either create a list outside the loop and add the node to the list within your loop, or, if you want to modify the query itself, use RETURN collect(m) as users (or, if you just want the numbers, RETURN collect(m.mobile) . If you did this, then you would get a single record back with a list of nodes (or mobile numbers).通过此查询,您将获得每个记录的一个节点,因此如果您需要一个列表,您可以在循环外创建一个列表并将该节点添加到循环内的列表中,或者,如果您想修改查询本身,使用RETURN collect(m) as users (或者,如果你只想要数字, RETURN collect(m.mobile) 。如果你这样做了,那么你会得到一个带有节点列表(或手机号码)的单条记录。

Instead of parsing record by record, you can get all the data using list() at once and then process it.您可以使用 list() 一次获取所有数据,然后对其进行处理,而不是逐条记录解析。

 List<Record> recordList = result.list();
 for (Record record : recordList) { 
   //Parsing code here
 }

Refer this: https://neo4j.com/docs/api/java-driver/1.0/org/neo4j/driver/v1/StatementResult.html#list--请参阅: https : //neo4j.com/docs/api/java-driver/1.0/org/neo4j/driver/v1/StatementResult.html#list--

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM