Key Within Populated Data
See original GitHub issueIs there a way to leave the ID in the populated object as opposed to it being replaced by the data?
This is the data:
goals: {
text: 'Something'
user: 'userId'
}
users: {
userId: { online: true }
}
This is the outcome of populate:
goals: {
text: 'Something',
user: { online: true }
}
Is there a way to make the outcome as follows:
goals: {
text: 'Something',
user: { user: 'userId', online: true }
}
or
goals: {
text: 'Something',
user: 'userId',
userData: { online: true }
}
The first option would be to include the key used in the populated object. The second option would be to specify the target child for populate values.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
node.js - Mongoose populate data key remove in got data
I'm using relation between two collection and I have collection schema like follow. ... When I pass query for Room Find and populate...
Read more >Mongoose v6.8.2: Query Population
Population is the process of automatically replacing the specified paths in the document with document(s) from other collection(s). We may populate a single ......
Read more >Mongoose Populate() Method - GeeksforGeeks
In MongoDB, Population is the process of replacing the specified path in the document of one collection with the actual document from the ......
Read more >How to use Populate in Mongoose & Node.js
Population is way of automatically replacing a path in document with actual documents from other collections. E.g. Replace the user id in a ......
Read more >Designing A Database Schema Cheatsheet - Codecademy
In PostgreSQL, a column can be designated as a primary key using the PRIMARY KEY keyword. For example, the example code shows two...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the custom
populatedDataToJS
version. I’ll try that tomorrow.In the future I think the option that you suggested would be the best way forward. I think in most cases retaining the key is not necessary, so doing this by default may bring more problems than it would solve. Simply adding
keyProp
like you suggested would be more than enough in cases where one wants to retain the key.Since having a custom query solves my problem, not sure if this issue should be closed or left for the discussions regarding the future implementation.
Thanks for all the great work!
This has been confirmed and is available in all
v1.3.0-*
pre-releases. Will be included inv1.3.0
and future versions.