Question

I am using neo4JClient to query a list of nodes in the graph and present them on the web browser as a table. In order to get data, the following code is used.

var query = client
    .Cypher
    .Match("DataSpace")
    .Return(DataSpace => DataSpace.As<DataSpace>());
var longBooks = query.Results;
    jsonString = JsonConvert.SerializeObject(longBooks, Formatting.None, settings);
    context.Response.Write(jsonString);

The graph contains various other nodes.

 The Resultset at the Browser Window is : 
 [{"DataSpaceName":"DS1","DataSpaceDescription":"First Dataspace"},{"DataSpaceName":"DS2","DataSpaceDescription":"Second Dataspace"},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]

There are empty nodes that get returned, which I think correlates to the other nodes in the graph.

Can I get rid of the Empty Nodes ?

Was it helpful?

Solution

The query returns all nodes because that's what you asked for. Your Neo4jClient query simply translates to this Cypher query:

MATCH DataSpace
RETURN DataSpace

In this case DataSpace is simply an identifier that represents every node, without additional constraints.

Do your DataSpace nodes have anything that separates them from other nodes, e.g. a label, a common node that they're all connected to, a unique property?

In case the nodes have a unique DataSpace label, you can for query them with:

var query = client
    .Cypher
    .Match("ds:DataSpace")
    .Return(ds => ds.As<DataSpace>());

In case DataSpaceName is a property that is only present on DataSpace nodes, you can try:

var query = client
    .Cypher
    .Match("ds")
    .Where("has(ds.DataSpaceName)")
    .Return(ds => ds.As<DataSpace>());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top