Populate Virtuals : not working 😞
See original GitHub issueHi, I am using mongoose 4.5.3.
As mentioned in the docs, http://mongoosejs.com/docs/populate.html
in Populate Virtuals
, I can’t produce desired results as mentioned.
There isn’t any members
field present inside return bands
doc. Are you sure this worked with you?
Can you please add a travis-ci tests for this?
My code:
var mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1/test');
var db = mongoose.connection;
/**************************************/
var personSchema = new mongoose.Schema({
name: String,
band: String
});
var bandSchema = new mongoose.Schema({
name: String
});
bandSchema.virtual('members', {
ref: 'Person', // The model to use
localField: 'name', // Find people where `localField`
foreignField: 'band' // is equal to `foreignField`
});
var Person = mongoose.model('Person', personSchema);
var Band = mongoose.model('Band', bandSchema);
var person = new Person({
name : 'Uday',
band : 'gnr'
});
person.save(function(){
var band = new Band({
name : 'gnr'
});
band.save(function(){
Band.find({}).populate('members').exec(function(error, bands) {
console.log(bands);
});
});
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:7
Top Results From Across the Web
why Virtual Populate not working on Node js and ...
But the problem is my virtual properties (In Product Model) not working as it doesnt show review of user in json format when...
Read more >Solved: Referencing a variable that hasn't been populated
The main problem arises when I try to call my Power Automate flow, which is configured to take both of the variables.
Read more >Solved: How can I auto populate email field, when user fie...
Solved: Dear Expert, How can I proceed with this requirement? Once the user field name is entered, the email field should automatically populate....
Read more >Solved: Merge Queries is not populating the information fo...
Data types are critical and can cause all sorts of issues if not set up properly, especially for merges and relationships in the...
Read more >How to populate a Value List with very variable data?
The Virtual List technique would work best for the the second method. ... and not have to write a pile of conditions around...
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
Ok. Got it. You must need to set
toObject : {virtuals:true},
option in your schema. I guess, you should mention that in the doc. That would be helpful.Got it, you also need to add option
toJSON : {virtuals : true}
.