NeojClient - How can I retrieve ALL nodes?

1,783 views
Skip to first unread message

DavidJBerman

unread,
Feb 22, 2012, 5:15:23 PM2/22/12
to Neo4j
Hello,
I'm exploring using NeojClient to interact with Neo4j using C#. I
am new to Neo4j, graph databases in general and Gremlin and Cypher.
I've been on the project website and the documentation there is not
extensive. I've been able to insert a node and retrieve the node
using the node ID. However, I'm trying to do some basic operations.
Can someone tell me how I can do some fundamentals using Neo4jclient
please?

1. How can I get all nodes?
In the Neo4j console I can do this:
START n=node(*)
RETURN n

This gives me all my nodes. I can't figure out how to do this in
Neo4jclient. I got close, I can get START n=node(1) but I can't
figure out how to get it for "*".

var client = new GraphClient(new Uri("http://localhost:7474/db/
data"));
client.Connect();
var query = new CypherFluentQuery(client)
.Start("n", client.RootNode)
.Return<data.Person>("n.Name as Name");

foreach (var node in query.Results)
{ do something }

2. How can I tell the query to return the data in the correct way for
serialization? I was getting errors about columns unless I told the
query to return "N.Name as Name". In this example, my Person class
only has one property, Name, but this will be cumbersome with more
fields and defeats the purpose of serialization.

3. Is there a better way I could be doing this query? is there a way
to do something like var Nodes = client.Get<data.Person>("*")?

Thank you.

David

James Thornton

unread,
Feb 22, 2012, 5:58:22 PM2/22/12
to ne...@googlegroups.com
You can execute this Gremlin script to get all the nodes/vertices:

g.getVertices()


And if you want all edges/relationships:

g.getEdges()

- James

Marko Rodriguez

unread,
Feb 22, 2012, 5:59:46 PM2/22/12
to ne...@googlegroups.com
Or, more concise:

g.V
g.E

Marko.

http://markorodriguez.com

DavidJBerman

unread,
Feb 22, 2012, 6:01:17 PM2/22/12
to Neo4j
Thank you for the input but how can I do this using c# with the
Neo4jClient library?

I'm a C# programmer and I want my server to utilize Neo4j for some
social features.

Dave

Marko Rodriguez

unread,
Feb 22, 2012, 6:05:59 PM2/22/12
to ne...@googlegroups.com

DavidJBerman

unread,
Feb 22, 2012, 6:12:08 PM2/22/12
to Neo4j
Thanks Marko, yes you sent me the link to the correct page and I found
this before. But as someone who doesn't know Gremlin, I'm not clear
on how to take the information shown on this page about doing a
Gremlin query and express my request for all nodes using the C# syntax
that this library requires.

Can anyone comment on how we can use this library to get all nodes?
Something like: graphClient.RootNode.OutV("*")?

Thank you.

David

Marko Rodriguez

unread,
Feb 22, 2012, 6:14:36 PM2/22/12
to ne...@googlegroups.com
Unfortunately, I'm not a C# guy and thus, don't know the library. Romiko is usually around on this list and he should be able to help you out.

If you are interested in learning Gremlin, you can download and play on your local machine using the REPL (terminal) and provided toy graph datasets.

Good luck,
Marko.

Marko Rodriguez

unread,
Feb 22, 2012, 6:20:55 PM2/22/12
to ne...@googlegroups.com
Me again,

>
> Can anyone comment on how we can use this library to get all nodes?
> Something like: graphClient.RootNode.OutV("*")?


Is there a method like graphClient.V() ? If so, thats the one.

Marko.

Michael Hunger

unread,
Feb 22, 2012, 6:23:46 PM2/22/12
to ne...@googlegroups.com
David,

right now the Neo4j REST API doesn't expose all-nodes and all-relationships directly b/c this kind of operation is not suited over the wire as it would result in transferring your whole database content in the RESTful json format (which is quite verbose).

What is your actual use-case?

The node(*) is a new syntax which might not yet be reflected in the Neo4jClient-API.

2. and 3. are for Romiko / Tatham to answer, Tatham is currently in London, he presented Neo4jClient at the Neo4j user group.

Michael

Tatham Oddie

unread,
Feb 23, 2012, 12:02:16 PM2/23/12
to ne...@googlegroups.com
Hi David,

Thanks for checking out the client.

> I've been on the project website and the documentation there is not extensive.

Which parts do you want expanded? We only want to document the .NET layer, not neo4j itself. Cypher support is only brand new, and still in flux, as the doco states.

> 1. How can I get all nodes?

We haven't got support for node(*) yet in our Cypher wrapper. I can add it quickly, but I'm wondering what you need it for? It sounds incredibly inefficient. It'd be like running SELECT * FROM EvveryTableEver in SQL.

> 2. How can I tell the query to return the data in the correct way for serialization?

Our current Cypher implementation is focussed on projections. I'm working in support for basic result sets next. In the meantime, Gremlin is an easier option.

> 3. Is there a better way I could be doing this query? is there a way to do something like var Nodes = client.Get<data.Person>("*")?

You need to start by modelling your graph a bit. Currently you have the assumption that every node is a person, and always will be, and there are no relationships.

If you can explain a little bit about what you want to store, we'll all be able to help you with that.

On a related note, I did a talk in London last night about neo4j for .NET devs. The recording should be online at http://skillsmatter.com/podcast/home/neo4j-dotnet/js-3423 in the next day or so.


-- Tatham

Tatham Oddie

unread,
Feb 23, 2012, 12:03:46 PM2/23/12
to ne...@googlegroups.com
Nope. We haven't exposed that set before as we've never used it ourselves.

(The library gets expanded out as we need each feature, and the need to query every single node ever just hasn't presented itself to us yet.)


-- Tatham

DavidJBerman

unread,
Feb 23, 2012, 1:51:11 PM2/23/12
to Neo4j
Hi Everyone,
Thanks for the replies. I was asking about getting all nodes
because I have started experimenting pushing nodes in and I want to
know how I can peek and see what's there, iterate over items in my
collection, that sort of thing. I can see that it would be useful to
be able to navigate over all nodes in a use case for exporting data
for example.

I'm really just warming up to learn the basic CRUD operations at
this point. My real world use cases are this:

1. For a Social Networking site, I will want to store nodes to
represent People, Places, Videos, and Websites, EmailAddress. Phone.
2. I want to store relationships like Fred knows Bob and Bob knows
Fred (2 way). Fred follows Steve; Steve follows Bob (1 way).
3. I want to store Fred has phone number 123 and email fr...@fred.com;
Bob know's Fred and know's Fred's phone number and Fred's email
address. Steve knows Fred's phone number but not his email address,
because Fred's number is in Steve's phone. We can now suggest to
Steve to add Fred even though Fred's email isn't in Steve's address
book.
4. Steve clicks on Fred's profile. Show Steve mutual friends in
common with Fred.
5. Steve knows Fred and Steve knows Bob. Show Steve people that the
people he knows know (2 degree friend recommendation search)
6. Steve likes Video "kitty surprise". Bob likes "kitty surprise".
Suggest "kitty surprise" video to Fred when he signs on - search for
Videos 2 or more friends like the video. (Same concept applies to
Places and Websites).


I'm trying to find examples that show me how to do these things using
C# code and I'm doing a lot of hacking to try to figure it out.

Is there such thing as a "type" of node, or do you just put a property
on it like "nodeType" and assign a value to that property and use it
for filtering?

David
Message has been deleted

Romiko Derbynew

unread,
Feb 23, 2012, 5:35:59 PM2/23/12
to Neo4j
Check source code here for a sample chat site.

https://bitbucket.org/romiko/frictionfree/src

There you can find samples of Neo4jClient in action.



On Feb 24, 9:33 am, Romiko Derbynew <romi...@gmail.com> wrote:
> var myNodes= graphClient
>             .RootNode
>             .Out<User>("HOSTS", a => a.Key ==
> agencyKey.ToLowerInvariant());
>
> On Feb 24, 5:51 am, DavidJBerman <berma...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi Everyone,
> >   Thanks for the replies.  I was asking about getting all nodes
> > because I have started experimenting pushing nodes in and I want to
> > know how I can peek and see what's there, iterate over items in my
> > collection, that sort of thing.  I can see that it would be useful to
> > be able to navigate over all nodes in a use case for exporting data
> > for example.
>
> >   I'm really just warming up to learn the basic CRUD operations at
> > this point.  My real world use cases are this:
>
> > 1. For a Social Networking site, I will want to store nodes to
> > represent People, Places, Videos, and Websites, EmailAddress.  Phone.
> > 2. I want to store relationships like Fred knows Bob and Bob knows
> > Fred (2 way).  Fred follows Steve; Steve follows Bob (1 way).
> > 3. I want to store Fred has phone number 123 and email f...@fred.com;

Romiko Derbynew

unread,
Feb 23, 2012, 7:25:26 PM2/23/12
to Neo4j
Hi,

You should have your nodes connected to relationships.

var User= graphClient
.RootNode
.Out<User>("BELONGS_TO", a => a.Username ==
"buddyluv").SingleOrDefault();

To answer your question, I advise you model the graph as Tatham
suggested, make sure your nodes are connected via meaningful
relationships.

e.g.
RootNode<-BELONGS_TO-User

so a USER belongs to RootNode as a silly example

So with the above in place, we can get ALL users, like this
var Users= graphClient
.RootNode
.Out<User>("BELONGS_TO");

You can also do Lucene Index Queries, but perhaps, get the basics down
on the DB model and basic queries. Some blog posts I have are here as
well, and I highly recommend you watch Tatham's Video, he is a
brilliant presenter.

http://romikoderbynew.com/2011/07/30/neo4jclient-primer/

when you get comfortable, you can play with the full text search,
built into the library.
http://romikoderbynew.com/2011/08/28/lucene-full-text-indexing-with-neo4j/

We need to update the docs on the website, I cannot promise when it
will be done, but we will get down to it when we find some free time.

On Feb 24, 5:51 am, DavidJBerman <berma...@gmail.com> wrote:
> Hi Everyone,
>   Thanks for the replies.  I was asking about getting all nodes
> because I have started experimenting pushing nodes in and I want to
> know how I can peek and see what's there, iterate over items in my
> collection, that sort of thing.  I can see that it would be useful to
> be able to navigate over all nodes in a use case for exporting data
> for example.
>
>   I'm really just warming up to learn the basic CRUD operations at
> this point.  My real world use cases are this:
>
> 1. For a Social Networking site, I will want to store nodes to
> represent People, Places, Videos, and Websites, EmailAddress.  Phone.
> 2. I want to store relationships like Fred knows Bob and Bob knows
> Fred (2 way).  Fred follows Steve; Steve follows Bob (1 way).
> 3. I want to store Fred has phone number 123 and email f...@fred.com;

Tatham Oddie

unread,
Feb 24, 2012, 5:19:56 AM2/24/12
to ne...@googlegroups.com

DavidJBerman

unread,
Feb 24, 2012, 2:02:42 PM2/24/12
to Neo4j
Thank you every one for your inputs.

D.


On Feb 24, 5:19 am, Tatham Oddie <tat...@oddie.com.au> wrote:
> David,
>
> The video is now up:http://skillsmatter.com/podcast/home/neo4j-dotnet/js-3724
>
> -- Tatham
>
>
>
>
>
>
>
> -----Original Message-----
> From: ne...@googlegroups.com [mailto:ne...@googlegroups.com] On Behalf Of Tatham Oddie
> Sent: Thursday, 23 February 2012 5:02 PM
> To: ne...@googlegroups.com
> Subject: RE: [Neo4j] NeojClient - How can I retrieve ALL nodes?
>
> Hi David,
>
> Thanks for checking out the client.
>
> > I've been on the project website and the documentation there is not extensive.
>
> Which parts do you want expanded? We only want to document the .NET layer, not neo4j itself. Cypher support is only brand new, and still in flux, as the doco states.
>
> > 1. How can I get all nodes?
>
> We haven't got support for node(*) yet in our Cypher wrapper. I can add it quickly, but I'm wondering what you need it for? It sounds incredibly inefficient. It'd be like running SELECT * FROM EvveryTableEver in SQL.
>
> > 2.  How can I tell the query to return the data in the correct way for serialization?
>
> Our current Cypher implementation is focussed on projections. I'm working in support for basic result sets next. In the meantime, Gremlin is an easier option.
>
> > 3.  Is there a better way I could be doing this query?  is there a way to do something like var Nodes = client.Get<data.Person>("*")?
>
> You need to start by modelling your graph a bit. Currently you have the assumption that every node is a person, and always will be, and there are no relationships.
>
> If you can explain a little bit about what you want to store, we'll all be able to help you with that.
>
> On a related note, I did a talk in London last night about neo4j for .NET devs. The recording should be online athttp://skillsmatter.com/podcast/home/neo4j-dotnet/js-3423in the next day or so.
>
> -- Tatham
>
> -----Original Message-----
> From: ne...@googlegroups.com [mailto:ne...@googlegroups.com] On Behalf Of DavidJBerman
> Sent: Wednesday, 22 February 2012 10:15 PM
> To: Neo4j
> Subject: [Neo4j] NeojClient - How can I retrieve ALL nodes?
>
> Hello,
>   I'm exploring using NeojClient to interact with Neo4j using C#.  I am new to Neo4j, graph databases in general and Gremlin and Cypher.
> I've been on the project website and the documentation there is not extensive.  I've been able to insert a node and retrieve the node using the node ID.  However, I'm trying to do some basic operations.
> Can someone tell me how I can do some fundamentals using Neo4jclient please?
>
> 1. How can I get all nodes?
>     In the Neo4j console I can do this:
>     START n=node(*)
>     RETURN n
>
>     This gives me all my nodes.  I can't figure out how to do this in Neo4jclient.  I got close, I can get START n=node(1) but I can't figure out how to get it for "*".
>
>  var client = new GraphClient(new Uri("http://localhost:7474/db/data"));  client.Connect();  var query = new CypherFluentQuery(client)
Reply all
Reply to author
Forward
0 new messages