For my application I would to have nested data inside a document. I am building an application where I need a parent object with properties which contains a list of other objects.
What is the proper way to do this via a MutableDocument in c#?
Example structure:
public class Parent {
string SomeProperty{ get;set; }
public ICollection Children {get; set;}
}
public class Child{
string SomeProperty{ get;set; }
}
This is a fairly general question: answers will vary depending on exactly how you plan to use the child documents.
One solution, of course, is to do exactly the same thing that one would do it a SQL database: each child object has a field called “parent” that contains the document id of the parent.
Another obvious solution is that each parent document contains a list of document ids for its children.
A Document basically contains JSON, so it allows nesting. If you want nested objects, then set a document property to be a dictionary or array, and add the nested objects to that.
Just note that
using very large objects hurts performance, since the whole object has to be read and written whenever it’s accessed.
query capabilities for nested objects (like searching all items in an array) are very limited and can’t take advantage of indexes.