Well, you should definitively invite your
here in order for him/her to supply the reasoning behind his/her remark. There are factors more important than that for performance. A indexed project.id will be a lot faster compared to a non-indexed projectId.
Functionally, I prefer to have a project: object.
- I can $project the whole project: object to get all and only the project attributes. Otherwise you have to project each and every project attributes if everything is at the top level. Adding a project attribute will need a code update to get the new attribute at the top level. There is nothing to do when it is nested.
- In your code you may pass the project: object to a function knowing that the function won’t be able to access or modify the other top level attributes.
- You do not have to do name mangling when the same attribute name would apply. Something like:
{
user : { id : 1 , name : steevej }
project : { id : 2 , name : data-warehouse }
}
vs
{
userId : 1 ,
userName : steevej ,
projectId : 2 ,
projectName : data-warehouse
}
- It is easier to expand the model from a single user/project to multiple user/project.
{
user : { id : 1 , name : steevej }
projects :
[
{ id : 2 , name : data-warehouse } ,
{ id : 3 , name : web-interface } ,
]
}
vs
{
userId : 1 ,
userName : steevej ,
projectId_0 : 2 ,
projectName_0 : data-warehouse ,
projectId_1 : 3 ,
projectName_1 : web-interface
}
Then each element of projects: could be processed by the same project functions directly. Otherwise you have un-mangle the name before calling the functions.
So please ask your senior dev to provide his/her input.