Is it possible to populate without `_id` ?
Problem
I checked the API http://mongoosejs.com/docs/populate.html and tried out. It seems that `populate` can only works on foreign `_id`. Even there is a `match` option, it just add more filtering condition on `_id` query condition. There is no way to just populate with fields not involved with `_id`. In my project, we keep the `_id` as ObjectId and has another field as auto-increment Number. For example, `customers` model has `_id` as Object and `cuid` as incremental number. Other collections just reference to `cuid` not to `_id`. Is would be great to be able to customize this? Is there any design limitation causing this feature missing?
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Is it possible to populate without `_id` ?
The ability to populate not just on a single other field but even on a set of fields is almost required to properly support sharding, which is a huge use case for us. For example, we have a collection "students" which may have a shard key for "subscription"; when we populate student data from our sections model (which contains an array of students) we have the subscription on the document but it
Trust Score
3 verifications
- 1
The ability to populate not just on a single other field but even on a set of fi
The ability to populate not just on a single other field but even on a set of fields is almost required to properly support sharding, which is a huge use case for us.
- 2
For example, we have a collection "students" which may have a shard key for "sub
For example, we have a collection "students" which may have a shard key for "subscription"; when we populate student data from our sections model (which contains an array of students) we have the subscription on the document but it will only look up based on the _id stored in "student" rather than allowing us to specify that it should also map the documents "assignment" field to "assignment" on the student.
- 3
Since we'd then be doing a lookup without the shard key when doing populate it r
Since we'd then be doing a lookup without the shard key when doing populate it renders sharding useless, requiring all shards to be hit to retrieve the data instead of just one.
- 4
This is something we would be willing to fund development for or even do ourselv
This is something we would be willing to fund development for or even do ourselves if we could get some guidance of where to do the work. It is a major need for our company (GradeCam).
Validation
Resolved in Automattic/mongoose GitHub issue #2562. Community reactions: 2 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep