I would like to get an array/object of my tags with the content of my objectId (found by user id).
userModel
var userSchema = new mongoose.Schema({
pseudo : { type : String },
fullname : { type : String },
password : { type : String },
email : { type : String },
//tags : { type : Array },
tags : [
{
objectId : { type : mongoose.Schema.Types.ObjectId, ref: 'tag'},
completed : { type : Boolean }
}
],
dateCreation : { type : Date, default : Date.now }
});
tagModel
var tagSchema = new mongoose.Schema({
name : { type : String },
alias : { type : String },
description : { type : String },
dateCreation : { type : Date, default : Date.now }
});
mongoose request
userModel.find({ _id : req.session.passport.user._id }).select('tags').populate('objectId', 'name alias').lean().exec(function (err, result) {
console.log(JSON.stringify(result));
});
console.log
[
{
"_id":"538efe4a3bb9d97018b90ee4",
"tags":[
{
"objectId":"538f25f7f4d621281b7376e9",
"completed":false,
"_id":"538f25f7f4d621281b7376ea"
}
]
}
]
I would like to get content of objectId :/ Like 'name', 'alias'...
I know that I can write two request to get content, but it's not optimized :/
Can you help me ?
Thanks,