question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Key Within Populated Data

See original GitHub issue

Is 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DeividasKcommented, Jan 26, 2017

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!

0reactions
prescottpruecommented, Feb 18, 2017

This has been confirmed and is available in all v1.3.0-* pre-releases. Will be included in v1.3.0 and future versions.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found