A senior dev told me that if I query for projectId it would be a faster query compared to
if I query for “project.id”.
Is this true?
I just wanted some confirmation and explanation as to why this is
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 }
}
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.