Question

I was looking at porting a small side project over to use Mongo, as it was getting more and more time consuming using Nhibernate for the current scenario.

I gave NoRM a try originally, and that had a branch which had support from cyclic references and worked fine, however I cannot find any documentation to indicate if the official c# driver supports it.

The situation and why I have a cyclic reference is because I have a location object, which contains a list of roads, each road has a link to another location. It is quite similar to a simple set of nodes in a pathfinder.

public class Location
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IList<Road> Roads { get; set; }
}

public class Road
{
    public Location From { get; set; }
    public Location To { get; set; }
}

Now the problem is I have a whole world built up out of these objects (they have more properties in the real scenario) and they all interlink, however without being able to handle cyclic references I am not sure how I can solve this problem, as each road needs to know a start and an end point.

I know one compromise is to just get rid of the location object, and instead have an Id that references the location, but then I have to query each sub location individually. This is only done once and then kept in memory as there is a huge map that contains all possible locations and all possible routes so quick paths can be found between points.

It may be a case of the Location and Roads are not suitable for a document storage approach and can be stored another way...

Was it helpful?

Solution

The official C# driver doesn't really support "references" at all. The value of a field can be an ObjectID, but the concept of joins or references is not really implemented in the official C# driver.

Of course, even with "reference" support, these drivers would still be executing multiple queries.

It may be a case of the Location and Roads are not suitable for a document storage approach and can be stored another way...

Given the cases you've described, I would suggest looking at a graph database. There are several popular ones including Neo4J, Microsoft's Trinity, sones' GraphDB and a host of others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top