I am redesigning a very normalized database using the much more flexible MongoDB. The current problem is that the existing structure doesn't support the new processes being implemented without changing the MySQL schema extensively. Rather than modify the existing system, MongoDB's philosophy seems to make more particle sense for the future of the business.
The business rules are the following:
A raw material must be tracked. Logs about this raw material will be made based on analysis. A raw material will be processed and transformed into a component. Logs about this multi-step transformation must be kept. A component will be processed into a part. Logs about this process must be kept. A part can be used in an assembly. Parts or assemblies can be shipped to customers. Also, the system of processes to complete the transformation is different for different materials. In addition, it needs to be dynamic in-case an optimized process is discovered.
Collections and Documents:
- Systems - a group of processes
- Process - a sub-document of systems that will have many processes per system
- Log - A timestamped log of information that will include data and facts recorded by either machines or operators. Logs will have different types depending on the process that they apply to. Each log entry will link back to one of the processes and components above.
- Raw Material - Tracking items in raw material
- Components - Tracking items which have been converted from raw material to components
- Parts - Tracking items which have been converted from components or raw materials
My question is regarding the relationships between parents and grandchild objects. Should I include them in the same document as sub-docs, IE (Grandchildren represent parts):
parent(Raw material): {
name: 'parent item'
desc: 'parent desc'
child(component from raw material processed): [
{
name: 'child name'
desc: 'child desc'
child-property: 'some property'
grandchild(a part): [
{
name: 'grandchild'
},
{ name: 'grandchild2'}
]
},
{
name: 'child name 2'
desc: 'child desc 2'
child-property: 'some property 2'
grandchild: [
{
name: 'grandchild of 2'
},
{ name: 'grandchild of 2 - 1'}
]
}
}
I anticipate a large number of grandchildren, what is the best way to deal with this?