populated virtuals are always an array
See original GitHub issuevirtual 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, whilefindOne
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:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top 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 >
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 Free
Top 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
@AleksMeshkov added a quick note about it in the populate docs 👍
Thanks for taking the time to look at this new feature and point out issues 👍