DEV Community

Discussion on: How to Create Relationships with Mongoose and Node.JS

Collapse
hemantparmar profile image
hemant-parmar

Great article. I am about to implement relations for my MEAN project.

A Couple of questions.
Q-1. Can I have multiple path in find().populate() method?
I have a Log collection, I was thinking to add 4 ObjectId type fields. i.e. client, service, executive, manager - of course apart from its own fields. Each of these are just one object. i.e. One Log entry will be associated with one Client, Service, Execute and Manager.

So I will need to add multiple path with their own select keys. Is that recommended?

And when on frontend, when the Log is displayed, I am planning to populate relevant fields from all these 4 (i.e. Client Name, ClientCategory, ClientSubCategory, ClientRating), (ServiceName, ServiceFreq), ExecName and ManagerName.

The Log display on frontend has Search and filter options on various fields. So when a user searches or applies filters the backend Mongoose query will run again, fetch the data and display.

Q-2: What would be the performance impact if the number of entries in Log collection is in the range to 5000 - 50,000, when I use Child Ref vs Parent Ref? Which one is recommended according to you in this case.

Thanks again
hemant