I'm trying to return a result from my mongoose find operation. I know a lot of question have already been asked for this but i think this is different. Here's my user :
var UserSchema = new mongoose.Schema({
variable: {type: mongoose.Schema.ObjectId, ref: 'Variable'}
});
My user have a method to retrieve his variable. Here's the problem.
UserSchema.methods.getVariable = function() {
//TODO ?
}
I don't know how to populate my field and then return the result of the populate...
I think you can just use populate
var UserSchema = new mongoose.Schema({
variable: {type: mongoose.Schema.ObjectId, ref: 'Variable'}
});
UserSchema.
findOne({your:"query"}).
populate('variable').
exec().
then(
user=>console.log("user is:",user)
);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments