MongoDb and self-regulatory objects

I am just starting to learn about mongo db and was wondering if I am not doing something wrong .... I have two objects:

public class Part 
{
    public Guid Id;
    public ILIst<Materials> Materials;
}

public class Material
{
   public Guid MaterialId;
   public Material ParentMaterial;
   public IList<Material> ChildMaterials;
   public string Name;
}

When I try to save this particular graph of objects, I get an error due to circular reference. My question is, is there any way around this? In WCF, I can add the IsReference attribute on the datacontract to true, and it serializes just fine.

+3
source share
4 answers

I was able to accomplish exactly what I needed using the modified driver from NoRM mongodb .

0
source

Which driver are you using?

In NoRM, you can create a DbReference like this:

public DbReference<Material> ParentMaterial;

Mongodb-csharp DbReferences, .

public DBRef ParentMaterial;

Database.FollowReference(ParentMaterial).

+1

, , , , ODB NoSQL, .

Hibernate, , - AT ALL , JOIN , b-.

Versant ( - ), , .

, , Java ODB... , , , .....

, 20 , , , )

+1

If you want to store object diagrams with relationships between them requiring multiple “joins” to get the answer, you are probably better off working with a SQL-style database. The document-oriented approach of MongoDB and others is likely to structure this differently.

Take a look at MongoDB nested sets , which offer some ways to represent such data.

0
source

Source: https://habr.com/ru/post/1774429/


All Articles