Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Graphs in RavenDB: What’s the Role of the Middle Man?

DZone's Guide to

Graphs in RavenDB: What’s the Role of the Middle Man?

Let's take a look at what the role of the middle man is in implementing graph queries. Explore this interesting challenge.

· Database Zone ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

imageAn interesting challenge with implementing graph queries is that you sometimes get into situations where the correct behavior is counter-intuitive.

Consider the case of the graph on the right and the following query:

image

This will return:

  • Source: Arava, Destination: Oscar

But what would be the value of the Edge property? The answer to that is…complicated. What we actually return is the edge itself. Let’s see what I mean by that.

image

And, indeed, the value of Edge in this query is going to be dogs/oscar.

image

This isn’t very helpful if we are talking about a simple edge like this. After all, we can deduce this from the Src –> Destination pair. This gets more interesting when the edge is more complex. Consider the following query:

image

What do you think should be the output here? In this case, the edge isn’t the Product property, it is the specific line that matches the filter on the edge. Here is what the result looks like:

image

As you can imagine, knowing exactly what edge led you from one document to another can be very useful when you look at the query results.

Get comfortable using NoSQL in a free, self-directed learning course provided by RavenDB. Learn to create fully-functional real-world programs on NoSQL Databases. Register today.

Topics:
database ,graph database ,ravendb ,tutorial ,ravendb tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}