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.

populated virtuals are always an array

See original GitHub issue

virtual population is using find method to do its population stuff, so result is always an array however relation can be one-to-one in many cases and this causes some redundant calculation

  • find searches over all collection, while findOne stops on first result
  • code have additional complexity in x.y[0].value this [0] is redundant it would be nice to have ability to specify a relation type in any acceptable way
XSchema.virtual("y", {
    ref: "Y",
    localField: "_id",
    foreignField: "x",
    singular: true // <-- here
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vkarpov15commented, May 16, 2017

@AleksMeshkov added a quick note about it in the populate docs 👍

1reaction
vkarpov15commented, Jun 25, 2016

Thanks for taking the time to look at this new feature and point out issues 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does mongoose populate virtual field as array instead of ...
I want to populate an object into a virtual field with mongoose as a JSON object, but it always returns an array with...
Read more >
Mongoose 4.5 Virtual Populate | www.thecodebarbarian.com
Having an array of blog post refs in the author document is bad because the 'posts' array will grow without bound, so an...
Read more >
Virtual Populate localField array - Automattic/mongoose - GitHub
I am using mongoose v4.5.3 I am not sure if there is any functionality to take localField as array of ids to map...
Read more >
Mongoose v6.8.2: Query Population
Just call the populate method on the query and an array of documents will be ... Mongoose will always query the same model...
Read more >
Virtuals | typegoose
Virtual -Populate is also supported by Typegoose ... justOne: true // when this is not set to "true", mongoose will always return a...
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