cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Return list of nodes with neo4j-driver Javascript

Hello, I was wondering if there was a native way with the driver to return a list of nodes, rather than looping through the data and flattening it out myself. There are also unneeded fields such as identity and labels for me.

I could simply do result.records[0]["_fields"][0].map( x => x.properties); But was hoping I could learn another way directly from either the driver or db.

E.x.
Query: CALL db.index.fulltext.queryNodes("myIndex", $search_query) YIELD node, score RETURN COLLECT(node) LIMIT $limit

Return data from query:

{
    "records": [
        {
            "keys": [
                "COLLECT(node)"
            ],
            "length": 1,
            "_fields": [
                [
                    { "identity": {
                            "low": 100,
                            "high": 0
                        },
                        "labels": [
                            "somelabel"
                        ],
                        "properties": {
                               "keys": "Values",
                               .
                               .
                               .
                               .
                          }
                    },
{ "identity": {
                            "low": 100,
                            "high": 0
                        },
                        "labels": [
                            "somelabel"
                        ],
                        "properties": {
                               "keys": "Values",
                               .
                               .
                               .
                               .
                          }
                    }
                     .
                    .
                    }]]

What I expect is simply an array of objects that only contain the properties, e.g. [{"key","value"....},{"key":"value",....}...]

If not I can write my own method, but this seems like a fairly common use case but I can't find ways to perhaps modify the query or driver to do what I need.

I'm using version 4.0.2 of the driver.

1 REPLY 1

+1 on this, also looking for docs Re. handling the QueryResponse.
Currently I've written some utility helper functions but they're a bit chunky.