Storing_TreeView_Structures_WithMongoDB
Storing_TreeView_Structures_WithMongoDB copied to clipboard
Broken behavior in case Tree structure Model an Array of Ancestors (update action)
Hi, In Tree structure Model an Array of Ancestors (update action) in your example in case document "LG" has childs - this code will break structure for them, because you updating list of ancestors for "LG", but do not update list of ancestors for childs of "LG" (and recursively for other sub^n-childs). This will lead to inconsistency of data and ultimately will break it. Example: {"_id":"Electronics"}, {"_id":"Other Electronics"}, {"_id":"LG", "parent":"Electronics", "ancestors":["Electronics"]} {"_id":"LG_phone", "parent":"LG", "ancestors":["Electronics","LG"]}
let's move "LG" from "Electronics" to "Other Electronics" new data will be: {"_id":"Electronics"}, {"_id":"Other Electronics"}, {"_id":"LG", "parent":"Other Electronics", "ancestors":["Other Electronics"]} {"_id":"LG_phone", "parent":"LG", "ancestors":["Electronics","LG"]}
Nice spot. Added to backlog. Feel free to open PR for proper example