mongoose
mongoose copied to clipboard
Feature: Flatten nested populate
Feature
As of right now we can have nested populate like so :
const street = await StreetModel
.findOne(
{ _id: districtId}
)
.populate({
path: 'district',
model: 'District',
populate: {
path: 'city',
model: 'City'
},
})
.lean();
This means in order to access city you will have to do the following street.district.city
Wanted behavior
I think we should allow an optional way to flatten the nested population in order to allow the response to have a better structure if desired, instead of having to access nested properties so in the end we can access district like so street.district and city like so street.city. I can make a PR but from/to which branch should it be ?
Use case
In a single nested level, this won't make much of a difference but for me, I had these kind of relations Region->city->district->sub-district->area->street :D, sometimes I need the street with all of the locations above it
@IslandRhythms Any updates ?? I can start a PR but on which branch ??
You can make a PR off master
any update @khaledosama999 ? it would be a nice feature!
@lucafaggianelli got hung up on work, working on it right now