I have received a legacy project, and the system uses simple two-layer structure: buildings -> zones to store every data. My mission is to POST data to all selected areas and sub-areas. However, I am told to develop extensively for future consideration of the different type of buildings. Therefore, I want to add two new layers to this structure. The terms in parentheses in the following structure are what I want to add:
buildings -> (AHU) -> zones -> (sub-zones)
It means the previous structure is "William Street" (collection) -> "AHU-B-Z1"
The new structure will look like "William Street" (collection) -> "AHU-B" -> "Z1" -> "A"
The structure of existing buildings collection looks like this:
{ zone:
[ { precooling: [Array],
name: 'AHU-B-Z1',
_id: 5aa96e045104165bc96916e8 },
{ precooling: [],
name: 'AHU-B-Z2',
_id: 5aa91e6412c17df1f81371d3 },
{ precooling: [],
name: 'AHU-B-Z3',
_id: 5aa9f1e6412c17df813171d2 } ],
_id: 5aa6596e04510bc9694116e7,
name: 'William Street',
coordinate: [ 14.2, -19.1 ],
yearlyEnergyCost: 100000,
__v: 17 }
However, the whole Node.js project is based on the logic of building/zone. For example,
router.get("/building/:buildingid/zone/:zoneid", controllerZone.getOneZone);
router.route("/building/:buildingid/zone")
.get(controllerZone.getZone)
.post(controllerZone.postZone);
How can I redesign the DB and Node.js more efficiently? Is there any better way to modify this structure with fewer efforts? Thanks.