如何在 Neo4j Go 驱动程序中解析路径

我正在尝试使用 Neo4j Go 驱动程序。


我已经编写了这个代码片段来获取从节点 1 到节点 5 的路径,但是无法正确获取 api 中提到的结果。


result, err = session.Run("match (n:Xyz{title:1}),(m:Xyz{title:5}),p=allShortestPaths((n)-[*]->(m)) return p",nil)


    if err != nil {

        return "",err

    }



    for result.Next() {

        keys := result.Record().Keys()

        fmt.Println(keys)

        values_NEO := result.Record().Values()

        nodes := values_NEO[0].Nodes()

        labels := nodes.Labels()

        fmt.Println(labels)

    }

我收到以下错误:


values_NEO[0].Nodes undefined (type interface {} is interface with no methods)

我的图表是这样的:

http://img3.mukewang.com/629dcd30000184a713600762.jpg

斯蒂芬大帝
浏览 161回答 1
1回答

隔江千里

我假设你正在使用这个驱动程序。result.Record().Values()返回[]interface{}。所以 的 类型values_NEO[0]是interface{},它没有一个名为 的方法Nodes()。具有该方法的类型是Path.我对 neo4j 不熟悉,但如果您希望values_NEO[0]使用 type Path,则必须输入 assert,如下所示values_NEO[0].(neo4j.Path).Nodes():
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go