MongoDB Tree Structure Multiple Parents, sum and multiply -
i trying build bill of materials mini-app.
the heirarchy image below shows how there number of assemblies (the 110 numbers) 1 or more parts (100 numbers) or assemblies nested below them.
currently data structured this:
collection.insert({'part_project': 998, 'part_number': 002, 'part_category_prefix': 1, 'part_type': 110, 'part_description': 'tier 2 assembly b', 'part_revision': 1, 'part_version': 'a', 'bill_of_material_usages': [{ 'bom_version': 'a', 'part_version': 'a', 'part_revision': 1, 'children': [ {'part_number': '998 1 3 100', 'quantity': 3}, {'part_number': '998 1 4 110', 'quantity': 1} ]}] }) there array called 'bill_of_material_usages' stores information part or assembly's children , versions referenced.
i'm trying figure out how represent in table each assembly lists of parts , sub-assemblies.
i'm trying figure out how add total quantities of part. means if assembly has 2 of assembly b , assembly b has 3 of part there total of 2*3=6 part a's.
any advice on how current data structure or better structure fantastic.
i'm using mongodb, flask, vis.js , google charts.
thanks!!
i solved using recursive function follows children branch of tree until last child has no further children. allows me build structured tree , calculate total number of instances of individual part.
recursive functions limited number of recursions possible (think inception) although limitation unlikely have impact use-case.
Comments
Post a Comment